我需要一些帮助,以Python创建高级数据结构。我使用该语言的时间不长,但是在存储数据时,它比PHP难得多。
最终,我想要这样的数据:
data[year][team] = { 'points' : 30, 'yards' : 800 }
[基本上,我需要能够通过年团队对来查找,检索,添加,编辑和删除json对象中的数据。有什么想法吗?
我认为最简单的方法就是使用“字典词典”。
data = {2014: {'Liverpool': {'points': 30, 'yards': 800}}}
这将允许您使用data[2014]['Liverpool']
以获取{'points': 30, 'yards': 800}
格。
添加一年:
data.update({2015: ....})
向一年添加团队:
data[2014].update({'ManU': ...})
更新年度团队组合:
data[2014]['Liverpool'].update({'points': 33, 'yards': 820})
等...