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