Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python Functional Workhorses Map

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

My Code Works in the REPL, but the output from the challenge is Bummer: reverse didn't accept an argument

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

def reverse(iterable):
    def switch(item):
        return item[::-1]
    return list(map(switch, iterable))
treehouse:~/workspace$ python                                                                                                              
Python 3.9.0 (default, Jan 21 2021, 00:46:14)                                                                                              
[GCC 5.4.0 20160609] on linux                                                                                                              
Type "help", "copyright", "credits" or "license" for more information.                                                                     
>>> backwards = [                                                                                                                          
...     'tac',                                                                                                                             
...     'esuoheerT',                                                                                                                       
...     'htenneK',                                                                                                                         
...     [5, 4, 3, 2, 1],                                                                                                                   
... ]                                                                                                                                      
>>>                                                                                                                                        
>>> def reverse(iterable):                                                                                                                      
...     def switch(item):                                                                                                                  
...         return item[::-1]                                                                                                              
...     return list(map(switch, iterable))                                                                                                      
...                                                                                                                                        
>>> frontwards = reverse(backwards)                                                                                                        
>>> frontwards                                                                                                                             
['cat', 'Treehouse', 'Kenneth', [1, 2, 3, 4, 5]]                                                                                           
>>>                                                                                                                                        

When I test my code in the REPL, I get a list with the iterable reversed. If I understood the reasoning behind the error I think I could probably figure it out on my own. But I don't get why my function wouldn't be accepting an argument.

Any help would be mightily appreciated.

I thought maybe the issue was the challenge didn't like me nesting a function in reverse, so I tried the following, but I got the same error:

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

def reverse(iterable):
    return [item[::-1] for item in iterable]

1 Answer

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Please disregard. I misunderstood what the challenge was asking.

The following passed the first part of the challenge:

maps.py
def reverse(item):
    return item[::-1]
>>> def reverse(item):                                                                                                                     
...     return item[::-1]                                                                                                                  
...                                                                                                                                        
>>> frontwards = reverse(backwards)                                                                                                        
>>> frontwards                                                                                                                             
[[5, 4, 3, 2, 1], 'htenneK', 'esuoheerT', 'tac']