Comment

Comment by delluminatus

Even knowing a lot about FP, I still found this worth skimming for the esoteric Python syntax. When it comes to constructing dictionaries with list comprehensions, I would always do something like this:

  dict([n, 2 ** n] for n in range(5))
But they pointed out an actual "dict comprehension" that I didn't even realize existed:

  { n: n ** 2 for n in range(5) }
And there is a similar "set comprehension":

  { n ** 2 for n in range(5) }
Always amazes me how you can use Python for so many years and still encounter new features in the language.
parent delluminatus 11 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton