Python Python Collections Tuples Stringcases

Emil Hejlesen
Emil Hejlesen
2,223 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
PRO
Dave Harker
Pro Student 15,049 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
2,223 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
Pro Student 15,049 Points

Anytime, glad you found it useful :smile:

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

adam n
adam n
46,490 Points
(('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)