I have a list of tuples
list_input = [("00", 1), ("10", 2), ("00", 3), ("10", 1), ("00", 2), ("11", 1)]
I want to convert this list of tuples into a dictionary in a way that values for the identical keys add up.
dict_output = {'00': 6, '10': 3, '11': 1}
Here is the code:
list_input = [("00", 1), ("10", 2), ("00", 3), ("10", 1), ("00", 2), ("11", 1)]
dict_output = {}
value = []
for i in range(len(list_input)):
key = list_input[i][0]
value.append(list_input[i][1])
dict_output[key] = value
print(dict_output)
This is the output:
dict_output = '00': [1, 2, 3, 1, 2, 1], '10': [1, 2, 3, 1, 2, 1], '11': [1, 2, 3, 1, 2, 1]}