Hacker News new | ask | show | jobs
by pierrebai 858 days ago
Of course, Python would have been way more awesome if they did not reject the much more reader-friendly and idiomatic:

  squared_div_by_3 = [
      for i in range(10):
          if i % 3 == 0:
              i**2
  ]
That is, just transforming the normal for loop and if into a list comprehension by surrounding it with brackets. It would even preserve the friendly forced blocking and indentation. Can you imagine?
2 comments

It's inspired by set-builder notation: https://en.wikipedia.org/wiki/Set-builder_notation
Nim has a `collect` macro which works exactly like this.