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

Abdullah Jassim
Abdullah Jassim
4,551 Points

I understand its a single string, but shouldnt the for loop work for all cases? Suggestions to make this work?

def stringcases(single_string):
    for item in (single_string):
        return tuple(item.upper())
        return tuple(item.lower())
        return tuple(item.title())
        return tuple(item[::-1])
stringcases.py
def stringcases(single_string):
    for item in (single_string):
        return tuple(item.upper())
        return tuple(item.lower())
        return tuple(item.title())
        return tuple(item[::-1])

1 Answer

Viraj Deshaval
Viraj Deshaval
4,874 Points

Strings are single thing and if you loop over it then it will loop over each letter. For example:

>>> string1 = "abcdefg hijklmn"                                                                                  
>>> for str1 in string1:                                                                                         
...     print(str1)                                                                                              
...                                                                                                              
a                                                                                                                
b                                                                                                                
c                                                                                                                
d                                                                                                                
e                                                                                                                
f                                                                                                                
g                                                                                                                

h                                                                                                                
i                                                                                                                
j                                                                                                                
k                                                                                                                
l                                                                                                                
m                                                                                                                
n               

You can see its looping over the string but it will give you each letter and not the single string.

Your need to modify your code so that it will return the string with tuple. Remove the for loop as it's not required and you need to only return the tuple. For example:

return (tuple1upper(), tuple2lower(), tuple3title(), tuple4reverse)

do something like this and you will definitely pass this challenge.