Skip to content

Commit 005bd0b

Browse files
authored
docs: refine docstring and simplify reverse_letters implementation
Updated the docstring for clarity and fixed formatting.
1 parent 3c88735 commit 005bd0b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

strings/reverse_letters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def reverse_letters(sentence: str, length: int = 0) -> str:
2-
"""
3-
Reverse all words that are longer than the given length of characters in a sentence.
4-
If unspecified, length is taken as 0
2+
"""Reverse all words longer than a given character length in a sentence.
3+
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,8 @@ 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
17+
for word in sentence.split()
1718
)
1819

1920

0 commit comments

Comments
 (0)