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!

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
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

Is a variable with a single letter Truthy?

Still having trouble with this quiz question. My for loop seems to be going but not adding to newword after it becomes what I think is truthy.

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

def reverse(arg):
    letlist = []
    for char in arg:
    newword = None
    count = len(letlist)
    for i in range(count - 1, -1, -1):
        print('i =' + str(i))
        if newword:
            newword + letlist[i]
            newword = letlist[i]
    return newword


1 Answer

A letter is truthy.

The line newword + letlist[i] does not change the value of newword. You could try newword += letlist[i].

With that change, your program would correctly reverse string inputs such as 'tac'. However, if you pass in [5, 4, 3, 2, 1], you will instead get 15, which is the sum of the array, and if you pass in ['t', 'a', 'c'], you will get 'cat' rather than ['c', 'a', 't'].