top | item 21927216

(no title)

twa927 | 6 years ago

That's very nice code and Python is non-functional. I love its generators.

That's my version to make it more "functional":

  from itertools import cycle, islice
  from operator import add

  fizz = cycle(['', '', 'Fizz'])
  buzz = cycle(['', '', '', '', 'Buzz'])
  strings = map(add, fizz, buzz)
  strings_or_nos = (s or i for i, s in enumerate(strings, start=1))
  print(list(islice(strings_or_nos, 100)))

discuss

order

raverbashing|6 years ago

Cool, you just need to join the list with '\n' before printing ;)