Reverse the order of words in a given string. Extra whitespace between words is ignored. >>> reverse_words("I love Python") 'Python love I' >>> reverse_words("I Love Python") 'Python Love I'
(sentence: str)
| 1 | def reverse_words(sentence: str) -> str: |
| 2 | """Reverse the order of words in a given string. |
| 3 | |
| 4 | Extra whitespace between words is ignored. |
| 5 | |
| 6 | >>> reverse_words("I love Python") |
| 7 | 'Python love I' |
| 8 | >>> reverse_words("I Love Python") |
| 9 | 'Python Love I' |
| 10 | """ |
| 11 | return " ".join(sentence.split()[::-1]) |
| 12 | |
| 13 | |
| 14 | if __name__ == "__main__": |