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

Code works locally but not in treehouse editor

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

def reverse(item): return list(map(lambda x: x[::-1], item))

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


def reverse(item):
    return list(map(lambda x: x[::-1], item))

It says 'reverse didn't accept an argument.'

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,460 Points

Wow! Truly impressive. You've done a great job. It's just more than the challenge actually needed. You only have to reverse the top-level members of the iterable, not reverse the members of the iterable:

# Task 1 of 2
# Create a function named 'reverse' that takes a single iterable item
# and returns a reversed version of that item.
def reverse(iter1):
    return iter1[::-1]

Yup, thanks :)

This way seemed more along the lines of the what the prior videos were getting at. Using the built in python stuff and casting it to a list

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

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

Refresh my memory on your code now, what does iter1[::-1] mean? I'm guessing its slicing the iterable and listing it in reverse..

I do run into an issue using the code in the very next challenge however? Why doesn't this work for me?

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

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

forwards= list(map(reverse,backwards))

I had misunderstood the task itself it seems, we had to just do item[::-1] in the first task