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 trialnopcoder
8,605 PointsNow 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?
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
nopcoder
8,605 PointsKenneth !!! ....... :) Ok, found it, you need to leave the list () call out. Found the same in the challenge for filters.
Ronny Kibet
47,409 Pointsforwards = map(reverse, backwards)
ARNOLD TINASHE NZIRA
12,269 Pointsdef reverse(word): return word[::-1]
forwards = map(reverse, backwards)
akak
29,446 PointsYou 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 :)
nopcoder
8,605 PointsThanks, 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
29,446 PointsWeird... 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.
Bartlomiej Damek
12,132 PointsHi, I have the same problem Bummer! forwards isn't a map.
def reverse(word):
return word[::-1]
forwards = list(map(reverse, backwards))
Kenneth Love
Treehouse Guest TeacherBecause you made a list
.
Duraen Kingsley
3,743 PointsHere'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)
Denis Watida Machaka
7,311 Pointsdef reverse(word): return word[::-1]
forwards = map(reverse, backwards)) reverse(backwards)
Bartlomiej Damek
12,132 PointsThanks Kenneth :)
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherI'd tell you to send back a list if that was what I wanted :)
nopcoder
8,605 Pointsnopcoder
8,605 PointsTouché! :)