[英]Python, pulling info from a dict made up of key, values in which the values are 3-tuples
I have a MapReduce program that returns the results of the computation as a dict that looks like the following: 我有一个MapReduce程序,该程序将计算结果作为字典返回,如下所示:
{'pods': (54802L, 25417L, 59877L), 'sash': (160573L, 97199L, 178836L), ...}
I am trying to pull the items in this dictionary to make use of the values in the 3-tuples, but I keep receiving an error KeyError: 0
when trying to parse through the errors in the code shown below (specifically on this line key, indicies = results[i]
) 我想拉的项目在这个字典使用的值在3元组,但我不断收到一个错误
KeyError: 0
试图通过如下所示的代码中的错误解析(特别是在这条线时key, indicies = results[i]
)
bloomFilter = [False] * 200000
for i in range(0, len(results)):
key, indicies = results[i]
bloomFilter[indicies[1]] = True
bloomFilter[indicies[2]] = True
bloomFilter[indicies[3]] = True
What is the proper way to pull the information from the dict so that I can make use of the values in the 3-tuples? 从dict中提取信息的正确方法是什么,以便我可以使用三元组中的值?
Also, can I use L
values as indicies in a array, or do I need to cast them to ints? 另外,我可以将
L
值用作数组中的索引,还是需要将它们转换为整数?
I would iterate over the results
dictionary like so: 我将像这样遍历
results
字典:
for key in results:
indices = results[key]
bloomFilter[indices[0]] = True
bloomFilter[indices[1]] = True
bloomFilter[indices[2]] = True
Note also that the indices
tuple is zero-indexed, meaning you'll need to extract the values starting with zero (not one) like the above code shows. 还要注意,
indices
元组是零索引的,这意味着您需要提取以零(不是一个)开头的值,如上面的代码所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.