I want unique duplicate values in a dict. It looks like this:
d = {
"a":1,
"b":2,
"c":2,
"d":3,
"e":4,
"f":5,
"g":1,
"h":2,
"i":2,
"j":1,
"k":1}
Here is what I did:
obj = d.values()
K = []
K = sorted(list(zip(*[(x,K.append(x)) for x in obj if not x in K])[0]
V=[]
for v1 in L:
V.append([k for k, v in obj.iteritems() if v == v1][0])
d_out = dict(zip(K, V))
1. So, will K, V be in the correct order? Also, it can be a bit complicated, can anyone give a simple solution for the unique dict value over them?
2. Is it possible to do the following:
for v1 in L:
V.append([k for k, v in obj.iteritems() if v == v1][0])
This does not work on my testing:
[V.append([k for k, v in obj.iteritems() if v == v1][0]) for v1 in L]
3. I realized that I can use the value of the exchange key to achieve this (a unique dict value by its value), but I have no idea how to select the key when the swap caused a conflict with this key:
dict((value, key) for key, value in my_dict.iteritems())
, , , , . , ? -, dict?
4.
"" python dict, , , , python dict?