Skip to content

Commit

Permalink
implemented the fizz_buzz_access function
Browse files Browse the repository at this point in the history
  • Loading branch information
fjebaker committed Dec 15, 2023
1 parent cfada11 commit b82547d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions manipulations/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b82547d

Please sign in to comment.