logoalt Hacker News

gilleain08/01/20251 replyview on HN

As they say, with perl there's more than one way to do it (TMTOWTDI) and with python there is only one way.

Both approaches have their merits. Like with maven, where I once saw a question on a forum that was like "how do I do X?" and the reply was basically "You can't, don't try to do so, as that's wrong".


Replies

tzs08/01/2025

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'))))
show 2 replies