mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +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:
|
||||
|
||||
"""
|
||||
Will convert the entire string to lowecase letters
|
||||
|
||||
|
@ -9,7 +8,6 @@ def lower(word: str) -> str:
|
|||
'hellzo'
|
||||
>>> lower("WHAT")
|
||||
'what'
|
||||
|
||||
>>> lower("wh[]32")
|
||||
'wh[]32'
|
||||
>>> 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
|
||||
# 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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -8,7 +8,6 @@ def upper(word: str) -> str:
|
|||
'HELLO'
|
||||
>>> upper("WHAT")
|
||||
'WHAT'
|
||||
|
||||
>>> upper("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
|
||||
# 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__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user