I am coding a function as follows:
def create_objection(name, position, **kwargs):
dicct = {'name':name,
'position':position}
print(len(kwargs))
dicct.update({'extra_info': kwargs})
return dicct
This function is supposed to get ALWAYS name and position, and eventually a collection of key/value pairs in for or dictionaries. what I want is the following way of working:
create_objection('c1',{'t':1})
Output:
0
{'name': 'c1', 'position': {'t': 1}, 'extra_info': {}}
When I try this, then I get an error:
create_objection('c1',{'t':1},{'whatever':[3453,3453]},{'whatever2':[34,34]})
The error:
TypeError Traceback (most recent call last)
/tmp/ipykernel_32291/2973311999.py in <module>
----> 1 create_objection('c1',{'t':1},{'tt':2,'ttt':'3'})
TypeError: create_objection() takes 2 positional arguments but 3 were given
And I would like to get:
{'name': 'c1', 'position': {'t': 1}, 'extra_info': [{'whatever':[3453,3453]},{'whatever2':[34,34]}]}
How to proceed?