From 9f5c00d5e8e297ce86eb248d1d8c9d01f9adba82 Mon Sep 17 00:00:00 2001 From: Lukas Esc <55601315+Luk-ESC@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:29:05 +0200 Subject: [PATCH] use str.upper instead of dict removed the dict using string.ascii_lowercase and uppercase and replace it with str.upper, also added another test case --- strings/capitalize.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 63603aa07e2d..e7f4900f1ada 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,6 +1,3 @@ -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 @@ -14,11 +11,12 @@ def capitalize(sentence: str) -> str: 'A' >>> capitalize("") '' + >>> 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:] + return sentence[0].upper() + sentence[1:] if __name__ == "__main__":