Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to pass a dictionary as argument in Python function?

I have a dictionary as follows

d = {'a' : 1, 'b' : 2, 'c' : 3}

How do I pass above dictionary as an argument to a python function?


1 Answer
Rajendra Dharmkar

In the code given below we pass given dictionary as an argument to a python function and then call the function which works on the keys/value pairs and gives the result accordingly

d = {'a' : 1, 'b' : 2, 'c' : 3}
def f(dict):
    for k, v in dict.iteritems():
        print k, 2*v
f(d)

OUTPUT

a 2
c 6
b 4
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.