mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
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:
@@ -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()
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user