【发布时间】:2016-07-21 12:39:45
【问题描述】:
我有一个非常大 (> 10GB) 的 JSON 文件,其中包含多个字典。
现在,我有一些其他词典的列表。
假设我希望在这个文件中找到字典,它匹配列表中字典的两个键的值,并最终从这些字典中提取第三个键的值。我该怎么做呢?
目前,这是我的想法:
def parse(file):
for l in file:
yield eval(l)
# list_of_dicts is the list containing the dictionaries
for i in range(0,len(list_of_dicts)):
generator_of_dicts = parse("huge_file.json")
for j in generator_of_dicts:
if j[key1] == list_of_dicts[i][key1] \
and j[key2] == list_of_dicts[i][key2]:
print j[key3]
break
有更好的方法吗?
【问题讨论】:
-
听起来你需要使用 real 数据库。
标签: python-2.7 dictionary