From 1f2d2dd95500b956e9cd75c417cea74f75c83a45 Mon Sep 17 00:00:00 2001 From: gahjelle Date: Thu, 28 Nov 2024 16:29:04 +0100 Subject: [PATCH] Final QA --- name-main-idiom/echo.py | 6 ++---- name-main-idiom/echo_args.py | 6 ++---- name-main-idiom/echo_demo.py | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/name-main-idiom/echo.py b/name-main-idiom/echo.py index 5b7b5d2d3c..940b7664b6 100644 --- a/name-main-idiom/echo.py +++ b/name-main-idiom/echo.py @@ -1,9 +1,7 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) if __name__ == "__main__": diff --git a/name-main-idiom/echo_args.py b/name-main-idiom/echo_args.py index b33a75f23e..4cad04ff4b 100644 --- a/name-main-idiom/echo_args.py +++ b/name-main-idiom/echo_args.py @@ -3,10 +3,8 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) def main() -> None: diff --git a/name-main-idiom/echo_demo.py b/name-main-idiom/echo_demo.py index 5e9f5bd9fa..fb7ff89fff 100644 --- a/name-main-idiom/echo_demo.py +++ b/name-main-idiom/echo_demo.py @@ -1,9 +1,7 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) if __name__ == "__main__":