diff --git a/strings/capitalize.py b/strings/capitalize.py index c0b45e0d9614..628ebffc8852 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: """ Capitalizes the first letter of a sentence or word. @@ -19,11 +16,9 @@ def capitalize(sentence: str) -> str: if not sentence: return "" - # Create a dictionary that maps lowercase letters to uppercase letters # Capitalize the first character if it's a lowercase letter # Concatenate the capitalized character with the rest of the string - lower_to_upper = dict(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__":