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

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

Function "not accepting argument"

Here's my code, I run it in another program and it seems to accept arguments just fine but when I run it in the Treehouse test it wont let me pass. Says 'reverse did not accept an argument'. Any ideas on why its saying this?

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

def reverse(var):
    newnie = list(var)
    awords = []
    for i in range(len(newnie), 0, -1):
        awords.append(newnie[(i-1)])
    awords = "".join(awords)
    return awords

1 Answer

Steven Parker
Steven Parker
229,582 Points

Perhaps you haven't tested this using all of the sample data. In particular, try it with the numeric list (reverse([5,4,3,2,1])) and see how your code performs with that.

Hint: there's a much easier way to implement this. Are you familiar with slices?

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

I for sure once was. I tried refamiliarizing myself with slices but it I was having trouble slicing a string and just started going this route.

Steven Parker
Steven Parker
229,582 Points

You can add more code to make this work with different kinds of iterables; but this might be a good time to review slices, since with that it becomes a one-liner.   :wink: