I need to add items to a counter and needs to be more dynamic.
hash_data = [{'campaign_id': 'cid2504649263',
'country': 'AU',
'impressions': 9000,
'region': 'Cairns',
'utcdt': datetime.datetime(2013, 6, 4, 6, 0)},
{'campaign_id': 'cid2504649263',
'country': 'AU',
'impressions': 3000,
'region': 'Cairns',
'utcdt': datetime.datetime(2013, 6, 4, 6, 0)},
{'campaign_id': 'cid2504649263',
'country': 'AU',
'impressions': 3000,
'utcdt': datetime.datetime(2013, 6, 4, 7, 0)}]
For example, then last element in the list of hashes does not contain region. Yet the below is how I add elements and will get an error.
C = Counter()
for item in hash_data:
C[item['utcdt'],item['campaign_id'], item['country'], item['region']] += item[metric]
Ideally something like this but of course not work
C = Counter()
for item in hash_data:
m1 = item.keys()
m2 = []
for i in ml:
if i!='impression':
ms.add(i)
C[ml] += item[metric]