-4

Python dictionary removes duplicates by default But i dont want to remove duplicates

Program

s = {"a":"s","a":"b","b":"d"}
print s

Output

{'a': 'b', 'b': 'd'}

Output which is expected

{'a':'s','a':'b','b':'d'}
Mounarajan
  • 1,357
  • 5
  • 22
  • 43
  • 2
    Dictionaries can only map keys to a value if those keys are unique; what would `s['a']` return otherwise? If you need to associate multiple values per key, use *lists or sets* for the values. – Martijn Pieters Apr 06 '16 at 13:03

1 Answers1

1

You should consider using other structure. Dictionary is a key-value so for each key there is only 1 value. Try using either list of tuples or for each key in dict store a list of values.

Alex
  • 1,141
  • 8
  • 13