A dict
dic = {
1: 'a',
2: 'a',
3: 'b',
4: 'a',
5: 'c',
6: 'd',
7: 'd',
8: 'a',
9: 'a'}
I want to remove duplicate values, just save one K / V pair. As for the “key” selection of these duplicate values, it can be max or min or randomly select one of these duplicate element keys.
I do not want to use k / v swap since it cannot control the key selection.
Take the value "a", for example
1: 'a',
2: 'a',
4: 'a',
8: 'a',
9: 'a'
the maximum key will be {9: 'a'}, and min will be {1: 'a'}, and random will choose any of them.
And if the key is another value of the hashed value, for example, a string, then how to make such a choice?
Can anyone share an idea?
Thank!