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! While you're at it, check out some resources Treehouse students have shared here.

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 Python Collections (2016, retired 2019) Tuples Stringcases

Muhammad Haseeb Alam
Muhammad Haseeb Alam
5,930 Points

My reverse code is not working

my reverse code not working

stringcases.py
def stringcases(mystring):
    mysent = mystring.split()
    newstring = []
    for words in mysent:
        wordlist = list(words)
        for al in wordlist:
            if al.isupper():
                bl = al.lower()
            elif al.islower():
                bl = al.upper()
            newstring.append(bl)
        newstring.append(" ")
        mylist = "".join(newstring)
    return (mystring.upper(), mystring.lower(), mystring.capitalize(), mylist)

1 Answer

Steven Parker
Steven Parker
231,269 Points

It looks like you're working too hard! Reversing a string doesn't require manipulating cases or splitting and reconstruction. In fact, it can be done in just one step using a slice with the proper arguments.

Also, for the 3rd item, the "capitalize" method does something different from what the instructions are asking for. But there is another string method that will do the right job.