Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndy McDonald
Python Development Techdegree Graduate 13,801 PointsTrouble counting backwards
I don't understand why my code isn't counting backwards.
backwards = [
'tac',
'esuoheerT',
'htenneK',
[5, 4, 3, 2, 1],
]
def reverse(var):
answer =[]
for itera in var:
print(itera)
for i in range(len(itera), -1):
print(len(itera))
answer.append(itera[i])
answer = "".join(answer)
return answer
print(reverse(backwards))
1 Answer
Steven Parker
231,268 PointsHere are a few hints:
- the instructions ask for a function "that takes a single iterable item", not all of them at once
- the function only needs to
return
the result, it doesn't need toprint
anything - in a
range
, you must specify a "stop" value along with a "step" - this code mismatches lists and strings, you might want to convert (split) the string first
- do you remember slices? They might provide an even easier way to do this task