Re:Functional Programming in Python [pdf]
by aaronchall on Friday July 24, 2015 @09:57PM
(#9946253)
Yes, in Python 2.7 onward:
s = {i**2 for i in range(10) if i}
and the colon is what makes the dict comprehension different from the set comprehension: d - {i:i**2 for i in range(10) if i}
With the dictionary comprehension you can just separate the key and value with a colon, which is more natural. It might just be sugar on top of a generator expression but it is definitely a special case, syntactically speaking.