I'm working with a dictionary, and I'm having a problem, so let's say I have two lists that I need to create a dict, I know, I can use zip to do this, but the thing is, the list I'm using for keys ( list1 ) have similar tuples. This is just an example, the lists can have more elements, but the len in both lists are always the same.
list1 = [(3, 2), (2, 4), (2, 4), (4, 3), (4, 2), (4, 3)]
list2 = [68, 34, 29, 29, 3, 59]
mydict = dict(zip(list1, list2))
print(mydict)
Output:
{(3, 2): 68, (2, 4): 29, (4, 3): 59, (4, 2): 3}
I know that the keys are unique, and if two keys are the same, the associated value will be the last one to appear, but what I need it's that if two keys are the same, then, the associated value needs to be the minimum. For example, in list1 I have two tuples repeated (2,4) with associated values of 34 and 29, so when the dictionary is created I need to keep the 29, and the other duplicated tuple is (4,3) with values of 29 and 59, and if the dictionary is created I want the value to be 29, not 59.
my desired output:
{(3, 2): 68, (2, 4): 29, (4, 3): 29, (4, 2): 3}
There is some way I can achieve this? Any help will be appreciated, thank you!