I have two lists created in python:
list1 = [2, 3, 3, 4, 4, 5] list2 = [-4, 8, -4, 8, -1, 2]
Now I have fixed these two lists in the dictionary as follows:
d = dict(zip(list1, list2))
which gives me:
{2: -4, 3: -4, 4: -1, 5: 2}
I want to get this result:
{2: -4, 3: 4, 4: 7, 5: 2}
list1 becomes the key to the new dictionary. If I have two values ββin list1 that are the same, I want them to add two values. For example, in list 2, 8, and -4, both have the same key 3. Is there a way to add these two values ββtogether so that the key looks like
{3: 4}
source share