Curly braces. Passing keyword arguments into dict()
, though it works beautifully in a lot of scenarios, can only initialize a map if the keys are valid Python identifiers.
This works:
a = {'import': 'trade', 1: 7.8}
a = dict({'import': 'trade', 1: 7.8})
This won’t work:
a = dict(import="trade", 1=7.8)
It will result in the following error:
a = dict(import="trade", 1=7.8)
^
SyntaxError: invalid syntax