0
I’m having trouble with my dict
. I need it not to delete duplicate key values. I have a style tuple lista_tupla = [(1, [1, 2, 3, 4]), (2, [5, 6, 7]), (3, [7, 8, 9]), (3, [10, 11, 12]), (4, [13, 14, 15])]
but when I use the command dict(lista_tuplas)
he turns into: {1: [1, 2, 3, 4], 2: [5, 6, 7], 3: [10, 11, 12], 4: [13, 14, 15]}
, soon, he replaced the duplicate key that was the 4 by the last value
found. How do I avoid this? It is mandatory that I keep both because although they are equal keys, the values between the keys are different! Help Please 0/ is urgent rsrs
One of the ways I thought was to do the following: first to go through the
lista_tupla
and for every equal key found, add a value to it by searching everyone with everyone, then it would look like this:lista_tupla = [(1, [1, 2, 3, 4]), (2, [5, 6, 7]), (3, [7, 8, 9]), (3, [10, 11, 12]), (4.0001, [13, 14, 15])]
But I don’t know how to do that because in fact every key of mine is a float, because it’s the result of an average. So adding a very small value is no problem.– Allan
But a dictionary with duplicate keys makes no sense. Why do you think you need a dictionary?
– Pablo Almeida
To convert into dictionary, either you join the values of the repeating keys, or do not use dictionary.
– Leonel Sanches da Silva
It would be interesting if I could clarify how to proceed in the event of a key conflict.
– Augusto Vasques