K
K
Katerina192019-11-08 22:00:23
Python
Katerina19, 2019-11-08 22:00:23

How to sum values ​​in a dictionary?

Good afternoon, colleagues!
Can you please tell me how to sum the values ​​in the dictionary by key, if the value is a list of numbers?
defaultdict(, {'JSC Vector-26': [24900, 143800, 107700, 27100, 105300, 59100, 131400, 37300, 12500, 43000, 49100, 82700, 112500, .....

import csv

from collections import defaultdict

fout = open('t.csv', 'w')

dict = defaultdict(list)

with open('input.csv') as File:

    reader = csv.reader(File, delimiter=';')

    for row in reader:

        a = int(row[1])

        b = row[0]

        dict[b].append(a)

print(dict)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question