Home > Blockchain >  passing dynamically all dictionary <key, value> as function arguments
passing dynamically all dictionary <key, value> as function arguments

Time:04-06

i got a given dictionary - for instance: x = {'a': 1,'b': 2, 'c': 3} what i would like to do is sending all keys and values to some function. for instance: func1(a=1,b=2,c=3)

(for other dictionary y = {'z': 8,'x': 9, 'w': 11,'p': 88} the function call will be: func1(z=8,x=9,w=11,p=88))

is it possible?

Thank you.

CodePudding user response:

These exemples might be useful. However it really depends on what's the final function

How to pass dictionary items as function arguments in python?

https://www.geeksforgeeks.org/python-passing-dictionary-as-arguments-to-function/

How to pass dictionary as an argument of function and how to access them in the function

CodePudding user response:

This is a built in feature of python, consider the following:

x = {'a': 1,'b': 2, 'c': 3}
func1(**x)

is the same as:

func1(a=1, b=2, c=3)

I recommend you read the documentation on defining fuctions

  • Related