2017 m. gruodžio 4 d., pirmadienis

python dictionary variable unpacking

>>> def color(red, green, blue, **kwargs):
...     print("r=", red)
...     print("g=", green)
...     print("b=", blue)
...     print(kwargs)


>>> k = {'red':10, 'green':11, 'blue':22, 'alpha':20}
>>> k = dict(red=10, green=11, blue=22, alpha=20) #or

>>> color(**k)
('r=', 10)
('g=', 11)
('b=', 22)
{'alpha': 20}