I have created a function
>>> fun(a,b,c):
print(a,b,c)
Which I can pass a list to, say [1,2,3]
by unpacking and we have
>>> fun(*[1,2,3])
1, 2, 3
or I can pass a dictionary d = {1:'a',2:'b',3:'c'}
>>> fun(*d)
1, 2, 3
However, I experience a problem when I attempt to unpack the keyword arguments
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: fun() keywords must be strings
and when I reverse the values and the keys d = {'a':1,'b':2,'c':3}
>>> fun(**d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: fun() got an unexpected keyword argument 'a'
So, two questions: Why does python only allow strings to be keyword arguments (or have I made a mistake)? And why, do I get an unexpected keyword argument when what it's referencing seems clear?