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 trialKir Ivanov
Courses Plus Student 52 PointsStrange behaviour of console?
backwards = [ 'tac', 'esuoheerT', 'htenneK', [5, 4, 3, 2, 1], ]
def reverse(arg): return reversed(arg)
This code does not suits test, If you have ideas why, please let me know =)
backwards = [
'tac',
'esuoheerT',
'htenneK',
[5, 4, 3, 2, 1],
]
def reverse(arg):
return reversed(arg)
2 Answers
Kourosh Raeen
23,733 PointsThere is no reversed() function in python. Try this:
backwards = [
'tac',
'esuoheerT',
'htenneK',
[5, 4, 3, 2, 1],
]
def reverse(arg):
return arg[::-1]
Chris Freeman
Treehouse Moderator 68,441 PointsThe issue is reversed() returns an iterator not a list. Wrapping the iterator with list()
converts the iterator output into a list and passes Task 1:
def reverse(arg):
return list(reversed(arg))
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsSee reversed() doc.
Kourosh Raeen
23,733 PointsKourosh Raeen
23,733 PointsMy mistake. I searched for it but I guess I didn't do a good job of it.