from collections import defaultdict
DATA = [
('1998-01-20', 8),
('1998-01-22', 4),
('1998-06-18', 8),
('1999-07-15', 7),
('1999-07-21', 1),
]
groups = defaultdict(int)
for date, value in DATA:
groups[date[:7]] += value
from pprint import pprint
pprint(groups)