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

Now use map() to create a variable forwards......

Trying this code for the solution of the challenge, i get a reversed but splitted list and the challenge cannot be completed. Unfortunately i just get something could not be reversed... What do i have to do to not get a splitted list?

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

def reverse(iterableitem):
    revitem = [] 
    for item in iterableitem[::-1]:
        revitem.append(item)

    return revitem

forwards = list(map(reverse, backwards))

9 Answers

Kenneth !!! ....... :) Ok, found it, you need to leave the list () call out. Found the same in the challenge for filters.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I'd tell you to send back a list if that was what I wanted :)

TouchΓ©! :)

Ronny Kibet
Ronny Kibet
47,409 Points

forwards = map(reverse, backwards)

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

forwards = map(reverse, backwards)

akak
akak
29,445 Points

You don't have to give back a list. map() applies each item from backwards variable to the function, so the function can five back just one variable at a time

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

forwards = list(map(reverse, backwards))

UPDATE: Ok, now I see you didn't make a list, just added one to the list, but still - map gives one item at a time so you don't have to use "for" loop :)

Thanks, for the hint. I was confused about the returned results by running it in my Python IDE. I ran your suggestion in the IDE and it worked as expected. Unfortunately using Code in the Challenge, it tells me that "forwards isnΒ΄t a map" ...... weired.

akak
akak
29,445 Points

Weird... I've just ran

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

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

forwards = list(map(reverse, backwards))

An it pass the challenge.

Hi, I have the same problem Bummer! forwards isn't a map.

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

forwards = list(map(reverse, backwards))

Here's my code. I was sure this was correct, and after checking the threads, it seems to be the popular answer. However, I am not passing the code challenge. Any insight? I'm getting Bummer! Not all items were reversed correctly. I'm inquiring about challenge 2 of 2 (forwards).

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

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

forwards = map(reverse, backwards)

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

forwards = map(reverse, backwards)) reverse(backwards)

Thanks Kenneth :)