mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Updated lower and upper (#2468)
* update lower and upper * 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
e92cd9d5c5
commit
72fe611462
|
@ -1,5 +1,4 @@
|
||||||
def lower(word: str) -> str:
|
def lower(word: str) -> str:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Will convert the entire string to lowecase letters
|
Will convert the entire string to lowecase letters
|
||||||
|
|
||||||
|
@ -9,7 +8,6 @@ def lower(word: str) -> str:
|
||||||
'hellzo'
|
'hellzo'
|
||||||
>>> lower("WHAT")
|
>>> lower("WHAT")
|
||||||
'what'
|
'what'
|
||||||
|
|
||||||
>>> lower("wh[]32")
|
>>> lower("wh[]32")
|
||||||
'wh[]32'
|
'wh[]32'
|
||||||
>>> lower("whAT")
|
>>> lower("whAT")
|
||||||
|
@ -19,9 +17,7 @@ def lower(word: str) -> str:
|
||||||
# converting to ascii value int value and checking to see if char is a capital
|
# 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
|
# letter if it is a capital letter it is getting shift by 32 which makes it a lower
|
||||||
# case letter
|
# case letter
|
||||||
return "".join(
|
return "".join(chr(ord(char) + 32) if "A" <= char <= "Z" else char for char in word)
|
||||||
chr(ord(char) + 32) if 65 <= ord(char) <= 90 else char for char in word
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -8,7 +8,6 @@ def upper(word: str) -> str:
|
||||||
'HELLO'
|
'HELLO'
|
||||||
>>> upper("WHAT")
|
>>> upper("WHAT")
|
||||||
'WHAT'
|
'WHAT'
|
||||||
|
|
||||||
>>> upper("wh[]32")
|
>>> upper("wh[]32")
|
||||||
'WH[]32'
|
'WH[]32'
|
||||||
"""
|
"""
|
||||||
|
@ -16,9 +15,7 @@ def upper(word: str) -> str:
|
||||||
# converting to ascii value int value and checking to see if char is a lower letter
|
# 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
|
# if it is a capital letter it is getting shift by 32 which makes it a capital case
|
||||||
# letter
|
# letter
|
||||||
return "".join(
|
return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)
|
||||||
chr(ord(char) - 32) if 97 <= ord(char) <= 122 else char for char in word
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user