mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fixed reverse words algorithm (#2469)
* updated reversed words * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
4a3b8d682e
commit
902fe1c907
|
@ -1,5 +1,6 @@
|
|||
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||
|
||||
|
||||
def binary_and(a: int, b: int):
|
||||
"""
|
||||
Take in 2 integers, convert them to binary,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||
|
||||
|
||||
def binary_xor(a: int, b: int):
|
||||
"""
|
||||
Take in 2 integers, convert them to binary,
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
# Created by sarathkaul on 18/11/19
|
||||
# Edited by farnswj1 on 4/4/20
|
||||
|
||||
|
||||
def reverse_words(input_str: str) -> str:
|
||||
"""
|
||||
Reverses words in a given string
|
||||
>>> sentence = "I love Python"
|
||||
>>> reverse_words(sentence) == " ".join(sentence.split()[::-1])
|
||||
True
|
||||
>>> reverse_words(sentence)
|
||||
>>> reverse_words("I love Python")
|
||||
'Python love I'
|
||||
>>> reverse_words("I Love Python")
|
||||
'Python Love I'
|
||||
"""
|
||||
return " ".join(reversed(input_str.split(" ")))
|
||||
return " ".join(input_str.split()[::-1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(reverse_words("INPUT STRING"))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
Loading…
Reference in New Issue
Block a user