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

"reverse" instruction- does it means to reverse each word , or to reverse the word sequence in a sentence ?

Not sure if the reverse refers to

  • reverse every word itself in a given sentence string
  • reverse the word sequence in a sentence
  • the input string will be only one word, reverse the letter of the word.

Thanks!

stringcases.py
def reverse(word):
    word_l= list(word)
    for index, letter in enumerate(word):
        word_l[len(word)-1-index] = letter
    return "".join(word_l)

def stringcases(string):
    word_list = string.split()
    word_list_new = word_list[:]
    for word in word_list:
        new = reverse(word)
        word_list_new.append(new)

    ans = string.upper(), string.lower(), string.title(), " ".join(word_list_new)
    print(ans)

Found the answer and fixed some bug.. this challenge is for "the input string will be only one word, reverse the letter of the word." Modifying string cases with function reverse would be okie

def stringcases(string): word_list = list(string) word_list_new = word_list[:] for index, word in enumerate(string): word_list_new[len(word_list)-1-index] = word

ans = string.upper(), string.lower(), string.title(), "".join(word_list_new)
print(ans)