mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
4d0a8f2355
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
28 lines
679 B
Python
28 lines
679 B
Python
from string import ascii_lowercase, ascii_uppercase
|
|
|
|
|
|
def capitalize(sentence: str) -> str:
|
|
"""
|
|
This function will capitalize the first letter of a sentence or a word
|
|
>>> capitalize("hello world")
|
|
'Hello world'
|
|
>>> capitalize("123 hello world")
|
|
'123 hello world'
|
|
>>> capitalize(" hello world")
|
|
' hello world'
|
|
>>> capitalize("a")
|
|
'A'
|
|
>>> capitalize("")
|
|
''
|
|
"""
|
|
if not sentence:
|
|
return ""
|
|
lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)}
|
|
return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from doctest import testmod
|
|
|
|
testmod()
|