Create a dictionary that has summary value from list / Combine two different dictionaries to summarize value

Viewed 328

I am new to python and working with dictionaries and list. Here is the list

detail = [(1, [u'apple', u'2017-07-03T08:03:32Z', 'boston']),


 (2, [u'orange', u'2017-07-03T08:58:35Z', 'NOLOCATION']),


 (3, [u'grape', u'2017-07-03T12:14:12Z', 'boston']),


 (4, [u'cherry', u'2017-07-04T13:16:44Z', 'new york']),


 (5, [u'strawberry', u'2017-07-06T10:56:22Z', 'san francisco']),


 (6, [u'plum', u'2017-07-06T10:56:22Z', 'seattle'])]

I want to summarize this, so that - for each date, I get split of counts for each location. Something like this -

details_summary = {'2017-07-03':[(boston,2), (NOLOCATION,1)], '2017-07-04':
[new york,1], '2017-07-06':[(san francisco,1),(seattle,1)]}

I want it in this format, because I want to generate map (visualization) for each date (key), and location points(value).

I ended up creating two different dictionaries that look like this -

location = {u'boston': 2, 'NOLOCATION': 1, u'new york': 1, u'san francisco': 
1, u'seattle': 1} 

date = {'2017-07-03':3, '2017-07-04':1, '2017-07-06':2}

Now, I want to summarize so that I get, split of counts in different location for each date and I am stuck here.

2 Answers
Related