Python Dictionaries to Functions

Passing Dictionaries to Functions

We can pass a dictionary to a function by passing the name of the dictionary. Let's define a function that accepts a dictionary as a parameter.

CopiedCopy Code

def fun(dictionary): 
   for i, j in dictionary.items(): 
print(i, '--', j)

A Python function to accept a dictionary and display its elements.

CopiedCopy Code

def fun(dictionary): 
   for i, j in dictionary.items(): 
      print(i, '--', j)
d = {'a':'Apple', 'b': 'Book', 'c': 'Cook'} 
fun(d)