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,418 Points

Trouble counting backwards

I don't understand why my code isn't counting backwards.

maps.py
backwards = [
    'tac',
    'esuoheerT',
    'htenneK',
    [5, 4, 3, 2, 1],
]
def reverse(var):
    answer =[]
    for itera in var:
        print(itera)
        for i in range(len(itera), -1):
            print(len(itera))
            answer.append(itera[i])
    answer = "".join(answer)
    return answer

print(reverse(backwards))

1 Answer

Steven Parker
Steven Parker
217,533 Points

Here are a few hints:

  • the instructions ask for a function "that takes a single iterable item", not all of them at once
  • the function only needs to return the result, it doesn't need to print anything
  • in a range, you must specify a "stop" value along with a "step"
  • this code mismatches lists and strings, you might want to convert (split) the string first
  • do you remember slices? They might provide an even easier way to do this task