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

Fictional Python: Create a function named reverse: Challenge Task 1 of 2

this code works in my shell but not in the challenge screen. Can someone please help:

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

def reverse (iter1):

    for item in iter1:
        return item[::-1]

1 Answer

Your problem is that you're telling a forloop to return you something. It won't. return exits the function and it won't run anymore, so your problem is that it's completing the first iteration of the loop and then it's done.

Hi jacinator,

Thank you. that was helpful. i tried something else, it didn't seem to work either. Works in my shell. The error was : reverse didn't accept an argument

def reverse (itr):

    new = []
    for item in itr:
        item = item[::-1]
        new.append(item)

    return new