Yes, you can use the dict()function to create a copy and add keyword arguments; use **{...}to add arbitrary keys that are not Python identifiers:
y = dict(x, **{2: 3})
, Python ( , ), dict():
y = dict(x, foo_bar='spam_eggs')
:
y = dict(x, foo='spam', bar='eggs', **{2: 3, 42: 81})
:
>>> x = {1: 2}
>>> dict(x, **{2: 3})
{1: 2, 2: 3}
>>> dict(x, foo_bar='spam_eggs')
{1: 2, 'foo_bar': 'spam_eggs'}
>>> dict(x, foo='spam', bar='eggs', **{2: 3, 42: 81})
{1: 2, 2: 3, 'foo': 'spam', 'bar': 'eggs', 42: 81}
>>> x
{1: 2}