Skip to content

Updated lower and upper #2468

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 25, 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
6 changes: 1 addition & 5 deletions strings/lower.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def lower(word: str) -> str:

"""
Will convert the entire string to lowecase letters

Expand All @@ -9,7 +8,6 @@ def lower(word: str) -> str:
'hellzo'
>>> lower("WHAT")
'what'

>>> lower("wh[]32")
'wh[]32'
>>> lower("whAT")
Expand All @@ -19,9 +17,7 @@ def lower(word: str) -> str:
# converting to ascii value int value and checking to see if char is a capital
# letter if it is a capital letter it is getting shift by 32 which makes it a lower
# case letter
return "".join(
chr(ord(char) + 32) if 65 <= ord(char) <= 90 else char for char in word
)
return "".join(chr(ord(char) + 32) if "A" <= char <= "Z" else char for char in word)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure but in my opinion this change causes a decrease of algorithm speed. Is comparing strings is not faster than comparing ints - in ord() case? @cclauss Your knowledge is need here! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone up for creating a timeit benchmark?



if __name__ == "__main__":
Expand Down
5 changes: 1 addition & 4 deletions strings/upper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ def upper(word: str) -> str:
'HELLO'
>>> upper("WHAT")
'WHAT'

>>> upper("wh[]32")
'WH[]32'
"""

# converting to ascii value int value and checking to see if char is a lower letter
# if it is a capital letter it is getting shift by 32 which makes it a capital case
# letter
return "".join(
chr(ord(char) - 32) if 97 <= ord(char) <= 122 else char for char in word
)
return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)


if __name__ == "__main__":
Expand Down