Skip to content

Commit 72fe611

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
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>
1 parent e92cd9d commit 72fe611

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

Diff for: strings/lower.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
def lower(word: str) -> str:
2-
32
"""
43
Will convert the entire string to lowecase letters
54
@@ -9,7 +8,6 @@ def lower(word: str) -> str:
98
'hellzo'
109
>>> lower("WHAT")
1110
'what'
12-
1311
>>> lower("wh[]32")
1412
'wh[]32'
1513
>>> lower("whAT")
@@ -19,9 +17,7 @@ def lower(word: str) -> str:
1917
# converting to ascii value int value and checking to see if char is a capital
2018
# letter if it is a capital letter it is getting shift by 32 which makes it a lower
2119
# case letter
22-
return "".join(
23-
chr(ord(char) + 32) if 65 <= ord(char) <= 90 else char for char in word
24-
)
20+
return "".join(chr(ord(char) + 32) if "A" <= char <= "Z" else char for char in word)
2521

2622

2723
if __name__ == "__main__":

Diff for: strings/upper.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ def upper(word: str) -> str:
88
'HELLO'
99
>>> upper("WHAT")
1010
'WHAT'
11-
1211
>>> upper("wh[]32")
1312
'WH[]32'
1413
"""
1514

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

2320

2421
if __name__ == "__main__":

0 commit comments

Comments
 (0)