How to pass a dictionary as argument in Python function?



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

 Example

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