|
|
|
|
|
by pcote
4912 days ago
|
|
I use dictionary comprehensions personally but I have mixed feelings about the syntax. It looks too much like set comprehensions on first glance. Compare the following to see what I mean. myset = {x for x in "This is my stuff".split()} mydict = {x:len(x) for x in "This is my stuff".split()} |
|
The advantage of this syntax is that : unambiguously introduces a key: value pair, whereas (key, value) could also occur in a list comprehension (e.g., by accident).