Advertisement
dprincef

Untitled

Mar 7th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def common_elements(my_dict): #Declares a function that accepts a dictionary as an argument
  2.     g = [] #An empty list that stores a common element that appears as a key and value
  3.     for i in my_dict: #Implementation of the program that checks if an element appears as a key and a value then prints the element/elements
  4.  
  5.         if i in my_dict.keys() and i in my_dict.values(): #Checks if an element appears in the key and value side
  6.  
  7.             g.append(i) #If True this appends such element to the variable g
  8.     print(g) #Outputs g
  9. my_dict = {
  10.     "A":"K",
  11.     "B": "D",
  12.     "C": "A",
  13.     "D": "Z"
  14. }
  15. common_elements(my_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement