8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a1d1a44 commit c38dec0Copy full SHA for c38dec0
strings/capitalize.py
@@ -0,0 +1,27 @@
1
+from string import ascii_lowercase, ascii_uppercase
2
+
3
4
+def capitalize(sentence: str) -> str:
5
+ """
6
+ This function will capitalize the first letter of a sentence or a word
7
+ >>> capitalize("hello world")
8
+ 'Hello world'
9
+ >>> capitalize("123 hello world")
10
+ '123 hello world'
11
+ >>> capitalize(" hello world")
12
+ ' hello world'
13
+ >>> capitalize("a")
14
+ 'A'
15
+ >>> capitalize("")
16
+ ''
17
18
+ if not sentence:
19
+ return ''
20
+ lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)}
21
+ return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:]
22
23
24
+if __name__ == "__main__":
25
+ from doctest import testmod
26
27
+ testmod()
0 commit comments