{"key1": val1, "key2": val2}
more idiomatic; I almost never came across a dict
with keyword arguments, and of course I was never tempted to write it. This is also more general because keyword arguments must be Python identifiers:
>>> {"foo bar": 1} {'foo bar': 1} >>> dict(foo bar=1) ------------------------------------------------------------ File "<ipython console>", line 1 dict(foo bar=1) ^ SyntaxError: invalid syntax >>> dict("foo bar"=1) ------------------------------------------------------------ File "<ipython console>", line 1 SyntaxError: keyword can't be an expression (<ipython console>, line 1)
source share