I am trying write pythonic code to reverse the words in a sentence
ex:
input: \"hello there friend\"
output: \"friend there hello\"
<
While there's not a whole lot wrong with wrapping it in a class, it's not exactly the most pythonic way to do things. Here's a shorter version of what you're trying to do:
def reverse(sentence):
return ' '.join(sentence.split()[::-1])
Output:
In [29]: reverse("hello there friend")
Out[29]: 'friend there hello'