Skip to content

Commit 75e0117

Browse files
its-100rabhtianyizheng02
authored andcommitted
Update capitalize.py (TheAlgorithms#10573)
* Update capitalize.py * Update strings/capitalize.py --------- Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
1 parent 7396b57 commit 75e0117

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: strings/capitalize.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
def capitalize(sentence: str) -> str:
55
"""
6-
This function will capitalize the first letter of a sentence or a word
6+
Capitalizes the first letter of a sentence or word.
7+
78
>>> capitalize("hello world")
89
'Hello world'
910
>>> capitalize("123 hello world")
@@ -17,6 +18,10 @@ def capitalize(sentence: str) -> str:
1718
"""
1819
if not sentence:
1920
return ""
21+
22+
# Create a dictionary that maps lowercase letters to uppercase letters
23+
# Capitalize the first character if it's a lowercase letter
24+
# Concatenate the capitalized character with the rest of the string
2025
lower_to_upper = dict(zip(ascii_lowercase, ascii_uppercase))
2126
return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:]
2227

0 commit comments

Comments
 (0)