Unpack and assign dictionary type arguments
When assigning a large number of arguments at once, it is very convenient to unpack and assign dictionary type arguments. I’ll write it down so I don’t forget.
github
- The file in jupyter notebook format on github is here .
google colaboratory
- If you want to run it on google colaboratory here
Author’s environment
sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G9323
Python -V
Python 3.8.5
Prepare a function with three arguments
def test(a,b,c):
print('a : ', a)
print('b : ', b)
print('c : ', c)
Unpack and assign a list type.
arg = [
'123',
'456',
'789',
]
test(*arg)
a : 123
b : 456
c : 789
Unpack and assign dictionary types.
arg = {
'a': '123',
'b': '456',
'c': '789',
}
test(**arg)
a : 123
b : 456
c : 789
This is a simple example, but I wrote it down so you can go back later.