Python Coding Challenge

Here is my solution for the Python Coding Challenge - Reverse Words
I included some comments to explain each step

def word_reverser(phrase): #taking the input string/sentence #and converting it into a list of strings word_list = phrase.split(' ') print(word_list) #taking the new list and reverseing it reverse_phrase = word_list[::-1] print(reverse_phrase) #converting the reversed list back to string return (' ').join(reverse_phrase) print(word_reverser('Codecademy rules')) #All tests pass
1 Like

Here’s a one-liner.

word_reverser = lambda s: ' '.join(s.split(' ')[::-1]) print(word_reverser('Codecademy rules'))

nice, short and sweet