I wrote a below python script to print all the values associated with keys in a python dictionary. I created python dictionary using values from rest api calls I made. The dictionary has duplicate keys.
dict = {'a':'b', 'a':'c', 'b':'d'}.
I have been through post Is there a way to preserve duplicate keys in python dictionary.
I am able to get the desired output using below script
import collections
data = collections.defaultdict(list)
val=input("Enter a vlaue:")
for k, v in (('a', 'b'), ('a', 'c'), ('b', 'c')):
data[k].append(v)
#print(list(data.keys()))
if str(val) in list(data.keys()):
for i in data[val]:
print(i)
I am struck at converting dictionary to tuple of tuples.
eg:
{'a':'b', 'a':'c', 'b':'d'}
to (('a', 'b'), ('a', 'c'), ('b', 'c'))
. Is there is a way to do this without changing the duplication value (I need duplicate keys)?