We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7396b57 commit 75e0117Copy full SHA for 75e0117
strings/capitalize.py
@@ -3,7 +3,8 @@
3
4
def capitalize(sentence: str) -> str:
5
"""
6
- This function will capitalize the first letter of a sentence or a word
+ Capitalizes the first letter of a sentence or word.
7
+
8
>>> capitalize("hello world")
9
'Hello world'
10
>>> capitalize("123 hello world")
@@ -17,6 +18,10 @@ def capitalize(sentence: str) -> str:
17
18
19
if not sentence:
20
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
25
lower_to_upper = dict(zip(ascii_lowercase, ascii_uppercase))
26
return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:]
27
0 commit comments