In [1]:
default = {'a': 1, 'b': 2}
override = {'a': 3, 'c': 4}
In [2]:
# previous way
final = default.copy()
final.update(override)
final
Out[2]:
In [4]:
# with PEP 448
final = {**default, **override}
final
Out[4]:
In [7]:
final = {'a': 1, 'b': 2, **override}
In [1]:
a = [1, 2, 3]
b = (4, 5, 6)
c = 'seven' # alone
d = (x ** 3 for x in range(2, 5))
e = {'a': None, 'b': False}
In [2]:
joint = a + b
In [3]:
joint = a + list(b) + [c] + list(d) + sorted(e)
joint
Out[3]:
In [22]:
joint = [*a, *b, c, *d, *sorted(e)]
In [21]:
joint
Out[21]:
In [28]:
'a: {} b: {} c: {}'.format(*[1, 2], 3)
Out[28]:
In [31]:
[(*t, 'love') for t in final.items()]
Out[31]:
In [7]:
def f(*args, **kwargs):
return args, kwargs
In [8]:
f(**{'x': 2}, **{'x': 3})
In [9]:
f(**{**{'x': 2}, **{'x': 3}})
Out[9]:
In [ ]: