← Back to context

Comment by tzs

2 days ago

There is usually more than one way to do it in Python, too. For example most people's Python fizzbuzz seem pretty different from mine:

  def fizzbuzz(n, *args):
    cur = ['' for x in range(1,n+1)]
    for m, postfix in args:
      cur = [y+postfix if x%m==0 else y for x, y in zip(range(1,n+1), cur)]
    cur = [str(x) if y == '' else y for x, y in zip(range(1,n+1), cur)]
    return cur

  print("\n".join(fizzbuzz(100, (3, 'fizz'), (5, 'buzz'))))

  The king wisely had the software developer beheaded,
  and they all lived happily ever after.

:)