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:
Du Yuanchao 2020-09-26 01:58:40 +08:00 committed by GitHub
parent e92cd9d5c5
commit 72fe611462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 9 deletions

View File

@ -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__":

View File

@ -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__":