I\'m reading in items:
for line in sys.stdin:
line = line.strip()
data = line.split(\"-\")
If I print data
as it is read,
Use a collections.Counter()
to count the occurrences:
import collections
lines = [['Adam', '5'],
['Peter', '7'],
['Adam', '8'],
['Lucy', '2'],
['Peter', '4']]
counter = collections.Counter()
for data in lines:
counter[data[0]] += int(data[1])
print(counter)
You'll get:
Counter({'Adam': 13, 'Peter': 11, 'Lucy': 2})