Advertisement
SamAyo2304

common_elements_dict

Apr 1st, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. my_dict = {
  2.     "A":"K",
  3.     "B":"D",
  4.     "C":"A",
  5.     "D":"Z",
  6. }
  7.  
  8. b=[]
  9. #function declaration
  10. def common_elements(my_dict):
  11.     for keys in my_dict:
  12.         #check the dictionary values
  13.         for items in my_dict[keys]:
  14.         #if the values are foundin the keys append it to list b
  15.             if items in my_dict:
  16.                 b.append(items)
  17.             #print a sorted version of b
  18.     print(sorted(b))
  19.              
  20.    
  21. common_elements(my_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement