From 0874d923bf91cfeccb4fdc3124bccde6f98b89e0 Mon Sep 17 00:00:00 2001 From: cefairman Date: Fri, 15 Dec 2023 16:37:56 +0000 Subject: [PATCH] implemented the fizz_buzzz_access function --- manipulations/library.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/manipulations/library.py b/manipulations/library.py index 8f2a8ff..0eed80a 100644 --- a/manipulations/library.py +++ b/manipulations/library.py @@ -2,6 +2,12 @@ T = TypeVar("T") +def _is_fizz_buzz(i: int) -> bool: + is_div_3 = i % 3 == 0 + is_div_5 = i % 5 == 0 + + return (is_div_3 or is_div_5) and not (is_div_3 and is_div_5) + def fizz_buzz_access(items: list[T]) -> list[T]: """ Access the list according to the fizz-buzz pattern, that is, elements @@ -10,4 +16,7 @@ def fizz_buzz_access(items: list[T]) -> list[T]: - is divisible by 3 or 5 - not divisible by 3 and 5 """ - return items + + + return [items[i] for i in range(len(items)) if _is_fizz_buzz(i)] +