dictionary - How do I add different numbers in multiple lines in python? -


so have file 9 different phone numbers. there line every call, , duration. want add duration of calls , match them own phone number.

here part of file:

    7803214567;94     7801234567;602     7801234567;910     7808765432;925     7801234567;631 

the first being phone number , second being duration in seconds. more clear, example: 7801234567, want add 602, 910 , 631 , match own phone number 7801234567.

it seems want count total number of minutes each unique phone number.

you use counter:

from collections import counter c = counter()  open("path/to/file.txt", 'r') f:     line in f:         k, v = line.split(";")         c += counter({k: int(v)})  >>> print(c) counter({'7801234567': 2143, '7808765432': 925, '7803214567': 94}) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -