diff --git a/strings/reverse_letters.py b/strings/reverse_letters.py index 4f73f816b382..c275664395dc 100644 --- a/strings/reverse_letters.py +++ b/strings/reverse_letters.py @@ -1,7 +1,7 @@ def reverse_letters(sentence: str, length: int = 0) -> str: - """ - Reverse all words that are longer than the given length of characters in a sentence. - If unspecified, length is taken as 0 + """Reverse all words longer than a given character length in a sentence. + + If ``length`` is not specified, it defaults to 0. >>> reverse_letters("Hey wollef sroirraw", 3) 'Hey fellow warriors' @@ -13,7 +13,7 @@ def reverse_letters(sentence: str, length: int = 0) -> str: 'racecar' """ return " ".join( - "".join(word[::-1]) if len(word) > length else word for word in sentence.split() + word[::-1] if len(word) > length else word for word in sentence.split() )