Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #my function
- def common_elements(a_dict):
- empty_list = [ ]
- for key, value in a_dict.items( ):
- if key in a_dict.keys( ) and key in a_dict.values( ): #if an element is both a value and key
- empty_list.append(key)
- print(empty_list)
- my_dict = {
- "A": "K",
- "B": "D",
- "C": "A",
- "D": "Z"
- } #Sample dictionary
- common_elements(my_dict) #This would return A and D because both A and D are values and keys in my_dict dictionary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement