Skip to content

Commit

Permalink
Merge pull request #2 from cefairman/main
Browse files Browse the repository at this point in the history
implemented the fizz_buzzz_access function
  • Loading branch information
cefairman authored Dec 15, 2023
2 parents 95ae45e + 0874d92 commit c1a4d94
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion manipulations/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]

0 comments on commit c1a4d94

Please sign in to comment.