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.
where am l getting it wrong..
Create a function named reverse that takes a single iterable item and returns a reversed version of that item
backwards = [ 'tac', 'esuoheerT', 'htenneK', [5, 4, 3, 2, 1], ] def reverse(iters): iters = ['this'] modified = list(map(reverseStr,iters)) return modified
Steven Parker210,837 Points
Did you peek ahead at code for task 2? You won't need "map" for task 1.
Here's a few hints:
- the "reverse" method should work with the argument, it should not replace it with literal data
- it should work with any kind of iterable (strings, lists, tuples, etc)
- a handy mechanism that works with all iterable types is a slice
James Arnold3,974 Points
Create a function named reverse that takes a single iterable item and returns a reversed version of that item.
Here we'll create our function - reverse - that takes in our list - backwards - and returns our reversed version. We'll do this by iterating through the list with a -1 step to reverse the order.
backwards = [ 'tac', 'esuoheerT', 'htenneK', [5, 4, 3, 2, 1], ] def reverse(iters): return iters[::-1]
Now use map() to create a variable named forwards. forwards should use reverse() to reverse the order of every item in backwards.
Now that we've got our function done, we'll come back to the global scope to create our forwards variable. Here we'll use map() to place in our function - reverse - and the object we want to iterate through - backwards.
backwards = [ 'tac', 'esuoheerT', 'htenneK', [5, 4, 3, 2, 1], ] def reverse(iters): return iters[::-1] forwards = map(reverse, backwards)