I have a for loop that goes over each row in a CSV and I create a dictionary that has a list in it, but the list gets overridden because the dictionary key is repeated several times. How do I sum up or append to the list in the second(1) position the next value for the same key the next loop iteration?
Because with append the value gets overridden if an existing key is found again so the values of the key gets overridden over and over.
with open('RawPolicy.csv', newline='') as rulemaker:
rmatcher = csv.reader(rulemaker, delimiter=" ")
for i in rmatcher:
dic[i[2]]=[i[0]],[i[1]]
The fields in the CSV are:
Sgrupo3 CSGrupo3 LLLLLLLL
Sgrupo4 CSGrupo4 LLLLLLLL
The output should be something like this:
{'LLLLLLLL': (['Sgrupo3', 'Sgrupo4'], ['CSGrupo3', 'CSGrupo4'])}