Skip to content

Commit 049a34d

Browse files
Tithi234pre-commit-ci[bot]MaximSmolskiy
authored
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>
1 parent 6f9f431 commit 049a34d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

strings/reverse_letters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def reverse_letters(sentence: str, length: int = 0) -> str:
22
"""
33
Reverse all words that are longer than the given length of characters in a sentence.
4-
If unspecified, length is taken as 0
4+
If ``length`` is not specified, it defaults to 0.
55
66
>>> reverse_letters("Hey wollef sroirraw", 3)
77
'Hey fellow warriors'
@@ -13,7 +13,7 @@ def reverse_letters(sentence: str, length: int = 0) -> str:
1313
'racecar'
1414
"""
1515
return " ".join(
16-
"".join(word[::-1]) if len(word) > length else word for word in sentence.split()
16+
word[::-1] if len(word) > length else word for word in sentence.split()
1717
)
1818

1919

0 commit comments

Comments
 (0)