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 trialSheng Chiu
1,372 Points"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!
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)
Sheng Chiu
1,372 PointsSheng Chiu
1,372 PointsFound 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