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 (Retired) Tuples Stringcases

what does the 'reversed version of the string' looks like? Isn't [uoy sevol esuoheerT] work?

reverse = ''.join(reversed(string.strip(' '))) not match

stringcases.py
# Handy functions:
# .upper() - uppercases a string
# .lower() - lowercases a string
# .title() - titlecases a string
# There is no function to reverse a string.
# Maybe you can do it with a slice?

2 Answers

Julien riera
Julien riera
14,665 Points

Hi Steven,

Have you tried something like :

def stringcases(string):
    a = string.upper()
    b = string.lower()
    c = string.title()
    d = string[::-1]
    tup = a, b, c, d
    return tup

Hi Julien,

I've tried your code string[::-1] -> 'uoY sevoL esuoheerT' it seems to be the similar result with mine ''.join(reversed(string.strip(' '))) -> 'uoY sevoL esuoheerT'

for string = 'Treehouse Loves You'

but somehow mine can't pass the challenge, but your solution is correct for this task, thanks :)

Steven Parker
Steven Parker
229,708 Points

Yes, that does work to reverse the string (and you don't need "strip").

But you still have a bit more work to do to satisfy the challenge. You still need to create a function, and the function must return a tuple that includes a lower case, upper case and title case version of the string as well as the reversed one.

And while the iterator reversed function does work, the challenge's suggestion of using a slice ("string[::1]") is more compact and doesn't need a join.

Maybe I made some misunderstand on this challenge, but I've tried several functions print ''.join(list(reversed(string[::1]))) ->uoy sevol esuoheert print list(reversed(string[::1])) ->['u', 'o', 'y', ' ', 's', 'e', 'v', 'o', 'l', ' ', 'e', 's', 'u', 'o', 'h', 'e', 'e', 'r', 't'] print ''.join(reversed(string.strip(' '))) ->uoy sevol esuoheert

But I still can't match the requirement of the task -> Create a function named stringcases that takes a string and returns a tuple of four versions of the string: uppercased, lowercased, titlecased (where every word's first letter is capitalized), and [a reversed version of the string].

what does the [a reversed version of the string] would be