3 comments

[ 3.0 ms ] story [ 12.2 ms ] thread
Today I learned that 4 lines of code is allowed to be billed as 2 lines of code.
I like how this solution uses several nice Python features; I found a way to simplify it further while still using the same overall approach:

  screams = {3: 'fizz',5:'buzz',21:'yaow'}
  for i in range(100):
      out = [screams[j] for j in screams if i%j == 0]
      print("".join(out) if out else i)
Edit: here's an even shorter version:

  screams = {3: 'fizz',5:'buzz',21:'yaow'}
  for i in range(100):
      out = "".join(screams[j] for j in screams if i%j == 0)
      print(out or i)
Source title is “Untitled”, and while unhelpful, is more accurate, as, whatever this is, it is not literally a two line version of anything.