Hacker News new | ask | show | jobs
by twa927 2364 days 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)))
1 comments

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