Skip to content

Instantly share code, notes, and snippets.

@pratik7368patil
Created May 30, 2020 15:10
Show Gist options
  • Select an option

  • Save pratik7368patil/69d95fc6cc80ad1ee3f307b989b6c045 to your computer and use it in GitHub Desktop.

Select an option

Save pratik7368patil/69d95fc6cc80ad1ee3f307b989b6c045 to your computer and use it in GitHub Desktop.
Reverse words in sentence
# This problem can be solved using split() and join()
def reverse_words(sen):
words = sen.split(' ') # split sentence into words
# then reverse a list of words and join them as a sentence
string = ' '.join(reversed(words))
print(string)
sen = "python is love"
reverse_words(sen)
# the output will be "love is python"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment