我是Python的新手,正在使用字典和列表。这是列表:
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'])]
我希望总结一下,对于每个日期,我想要得到每个位置的计数拆分。类似这样 -
details_summary = {'2017-07-03':[(boston,2), (NOLOCATION,1)], '2017-07-04':
[new york,1], '2017-07-06':[(san francisco,1),(seattle,1)]}
我希望以这种格式,因为我想为每个日期(键)和位置点(值)生成地图(可视化效果)。
我最终创建了两个不同的字典,看起来像这样 -
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}
现在,我想总结一下,为了得到每个日期的不同位置的拆分计数,并且我现在被卡住了。
print(detail)
,检查detail
变量的值。也许你不小心用int
覆盖了它? - AGN Gazer