1

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.

1
  • 2
    use ** like so: func1(**my_dict) Commented Apr 6, 2022 at 9:41

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.