Refine docstring and simplify reverse_letters implementation (#14205)

* docs: refine docstring and simplify reverse_letters implementation

Updated the docstring for clarity and improved the logic for reversing words.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update reverse_letters.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
Tithi Joshi
2026-03-09 10:00:39 +05:30
committed by GitHub
parent 6f9f4318af
commit 049a34d62b

View File

@@ -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
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()
)