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 trial

Python Functional Python Functional Workhorses Map

Tim Enders
Tim Enders
11,288 Points

Stuck on Task 2

So, this doesn't make much sense. I have completed step 1, so I would assume the definition of reverse() is perfectly fine. Then the map() call applies reverse() to each item in backwards, 'tac', 'esuoheerT', etc. Which is what I have been asked to do. Reverse each item in backwards.

However I get an error that says not all items were reversed correctly.

I have tried taking off the list() calls, but that always throws a new error.

maps.py
backwards = [
    'tac',
    'esuoheerT',
    'htenneK',
    [5, 4, 3, 2, 1],
]

def reverse(item):
  return list(reversed(item))

forwards = list(map(reverse, backwards))
Tim Enders
Tim Enders
11,288 Points

So worked on this in workspaces... This code returns the right answer for Task 2, but does not pass Task 1...

backwards = [ 'tac', 'esuoheerT', 'htenneK', [5, 4, 3, 2, 1], ]

def reverse(item): return list[::-1]

forwards = list(map(reverse, backwards))

2 Answers

There is no need for calling list()

I'm pretty sure this should work ;)

backwards = [
     'tac',
     'esuoheerT',
     'htenneK',
     [5, 4, 3, 2, 1],
 ]

def reverse(item):
   return item[::-1]

forwards = map(reverse, backwards)
akak
akak
29,445 Points

You are very close:

backwards = [
     'tac',
     'esuoheerT',
     'htenneK',
     [5, 4, 3, 2, 1],
 ]

def reverse(item):
   return item[::-1]

forwards = list(map(reverse, backwards))
Tim Enders
Tim Enders
11,288 Points

Thanks. Now I see that I mistyped when moving from workspace to challenge (Anyone know why that copy/paste doesn't work?).