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

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree
Andy McDonald
Python Development Techdegree Student 6,643 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
217,574 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
Andy McDonald
Python Development Techdegree Student 6,643 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
217,574 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: