Skip to content

Fixed reverse words algorithm #2469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bit_manipulation/binary_and_operator.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions bit_manipulation/binary_xor_operator.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
17 changes: 7 additions & 10 deletions strings/reverse_words.py
Original file line number Diff line number Diff line change
@@ -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()