0

I have this dictionary and I don’t want to print (the key and the value) if they already exist (as value and key) or vice versa.

I want to print (orange and apple) and (Strawberry and Grapes) for once.

{
'Orange'    : ‘Apple’,
‘Orange'    : ‘Banana’, 
’Strawberry': ‘Grapes’, 
‘Apple'     : ‘Orange’,
‘Blackberry': ‘Banana’, 
’Cherry'    : ‘Fig’, 
’Grapes'    : ‘Strawberry’ 
 }

Expexted output:

Orange Apple
Orange Banana
Strawberry Grapes
BlackBerry Banana
Cherry Fig
  • 2
    You can't have a dictionary with duplicate keys. If "Orange" is the key for "apple", it can't be the key for "banana". Please provide an actual legal dictionary. – Kevin Feb 04 '16 at 19:34

1 Answers1

2

Having duplicate keys sort of violates the purpose of a dictionary in python. There are ways around it like here but I wouldn't suggest it.

Community
  • 1
  • 1
Leustad
  • 375
  • 1
  • 5
  • 20