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 Hughes
Andy Hughes
8,114 Points

Trying to reverse the list, but I'm stuck!

I have been trying to do this challenge for a while and totally stuck.

I've looked at community answers and many seem to use


inside their function. Where does that come from in relation to the videos on 'Sorting' and 'Map'? I can't seem to find anything like this when watching videos back.

My code below looks like the sort of thing Kenneth covered in the videos, but clearly it's incorrect.

Once again, some guidance would be appreciated please. :)

backwards = [
    [5, 4, 3, 2, 1],

def reverse(item):
    return sorted(backwards, key=itemgetter([]), reverse)

1 Answer

Steven Parker
Steven Parker
217,577 Points

Advanced courses like this one assume you are familiar with the concepts presented in the beginner series. Slices aren't discussed in this course, but they were in the Slices video (the part about reversing starts at time 2:58) from the beginner-level course Python Sequences. And task 1 is just preparation for task 2 where you will use map.

There are a number of syntax and logical issues with the code here:

  • the parameter item isn't being used in the function
  • nothing has been defined for the identifier "backwards" to refer to
  • the itemgetter helper needs specific index value(s) as argument(s)
  • the "key" is not needed since the function only needs to work with simple iterables
  • the syntax for reversing in sorted is "reverse=True"
  • sorting isn't a viable approach to the task

An example of why sorting won't help is that "tac" sorted would be "act", or "tca" if sorted in reverse. But what the challenge is expecting to see when reversing "tac" is "cat".

Hint: a slice is well-suited to this task, or it could be done (with more steps) in a loop.

Andy Hughes
Andy Hughes
8,114 Points

Thank you Steven Parker. I totally get the assumption that I should be familiar with the basics, having done the course. In reality, the lack of daily repetitive use of the basics means it is easily forgotten. Hopefully in time, through repeated use, it will stay in my head. :).

Thanks also for a comprehensive answer. I've moved through the course quite quickly and so I'm still just too new to quite understand some of the things you're mentioning. But hopefully that's just time and practice.

I guess it's like going out for a driving lesson and then being expected to remember it all in the next lesson. It takes practice and repetition. :)

Steven Parker
Steven Parker
217,577 Points

You are so right about time and practice! :+1: And learning where to find info about things is at least as important as remembering thing things themselves (I certainly don't remember it all).

Happy holidays!   :christmas_tree: