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

Emil Hejlesen
Emil Hejlesen
3,014 Points

stringcases.py

i dont know why this doesnt work

stringcases.py
def stringcases(string):
    return ((string.upper(),), (string.lower(),), (string.capitalize(),), (string[::-1]),)

2 Answers

Dave Harker
PLUS
Dave Harker
Courses Plus Student 15,510 Points

Hi Emil Hejlesen,

Really close. The challenge requires that you title case the string for the third element of the returned tuple, you've capitalized it - You'll need to use .title() not .capitalize()

Also, I'm not sure why you've added the additional ,), around each element ... you're effectively returning a tuple containing single element tuples (kinda!) ... instead just try:

    return string.upper(), string.lower(), string.capitalize(), string[::-1]

If you really want to separate the elements, you could use:

return (string.upper()), (string.lower()), (string.capitalize()), (string[::-1])
# or hardcore/my eyes are burning mode
return ((string.upper()), (string.lower()), (string.capitalize()), (string[::-1]))
# but it isn't necessary and I think makes it harder to read

Great effort though :smile: keep up the good work and happy coding,
Dave :dizzy:

Emil Hejlesen
Emil Hejlesen
3,014 Points

hi dave

it was the .capitalize() that was wrong, i changed it to .title() and the thing with the () was just to try and structure it for me but i didn't help, thank you for the help :)

Dave Harker
Dave Harker
Courses Plus Student 15,510 Points

Anytime, glad you found it useful :smile:

Best of luck moving forward, and happy coding
Dave :dizzy:

(('HI THERE',), ('hi there',), ('Hi there',), 'ereht ih')

^ that's some sample output i get with your function. Is that what the challenge wants from you?

Remember that an easy way to make something into a tuple is putting a comma after each item:

bob = 1, 2, 3, 4
# becomes (1, 2, 3, 4)