From 005bd0b464871fe93d22ccb36c77309683cf315f Mon Sep 17 00:00:00 2001 From: Tithi Joshi Date: Wed, 21 Jan 2026 11:20:30 +0530 Subject: [PATCH 1/2] docs: refine docstring and simplify reverse_letters implementation Updated the docstring for clarity and fixed formatting. --- strings/reverse_letters.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/strings/reverse_letters.py b/strings/reverse_letters.py index 4f73f816b382..560dcd3f8d1f 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,8 @@ 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() ) From 008acf04b1b2f585a13000829cca6178a67bc3cc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Jan 2026 05:52:04 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/reverse_letters.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/strings/reverse_letters.py b/strings/reverse_letters.py index 560dcd3f8d1f..c275664395dc 100644 --- a/strings/reverse_letters.py +++ b/strings/reverse_letters.py @@ -13,8 +13,7 @@ def reverse_letters(sentence: str, length: int = 0) -> str: 'racecar' """ return " ".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() )