def word_reverser(phrase):
return " ".join(reversed(phrase.split()))
print(word_reverser(‘Codecademy rules’))
def word_reverser(phrase):
return " ".join(reversed(phrase.split()))
print(word_reverser(‘Codecademy rules’))
Hi! This is the way I solved it!
all you gotta do is
def word_reverser(phrase):
phrase_split = phrase.split(’ ')
new_phrase=list(reversed(phrase_split))
reversed_phrase = ’ '.join(new_phrase)
return reversed_phrase
def word_reverser(phrase) :
#split the phrase (type : list)
splitting = phrase.split(sep=" ")
#Rearrange the phrase (type : list)
new_list_of_phrase = splitting[::-1]
#Joining together into one sentence (type : string)
join = " ".join(new_list_of_phrase)
return join
print(word_reverser(‘Codecademy rules’))
def word_reverser(phrase):
phrase_l = phrase.split(" ")
r_phrase =
for index in range(len(phrase_l),0,-1):
print (index)
r_phrase.append(phrase_l[index-1])
print(r_phrase)
return " ".join(r_phrase)
print(word_reverser(‘Codecademy rules’))
One liner
def word_reverser(phrase):
# Write your code here
return " ".join(phrase.split()[::-1])
print(word_reverser('Codecademy rules'))
Hey!
When you do a slice, if you step negatively, we can start counting at the back already? So no need to [-1::-1] ?
Thanks for that.
What was your thought process when you went for a list comprehension? I’m still new to this and I can’t understand how your function works.
def word_reverser(phrase):
phrase = phrase.split()
reversed_phrase = phrase[::-1]
return " ".join(reversed_phrase)
print(word_reverser(‘hello how are you’))
This took me way longer than it should lol LOVING the challenges
def word_reverser(phrase):
x = reversed(phrase.split(" "))
return " ".join(x)
print(word_reverser('Codecademy rules'))