[英]Extract identical key, value from a dict in Python
I have a dict (dict_genes) containing gene id's as the keys. 我有一个字典(dict_genes),其中包含基因ID作为键。
I want to iterate through this dict and use the gene id's (keys) to extract values from another dict (seq_depth) such as: 我想遍历此字典,并使用基因ID的(键)从另一个字典(seq_depth)中提取值,例如:
for key, value in dict_genes.items():
print(seq_depth[key])
The dict seq_depth contains several identical gene id's and with this approach only one occurrence is printed where I want all of the gene id's printed if the match the key in the iteration (including indenticals). dict seq_depth包含多个相同的基因ID,并且通过这种方法,仅打印一次出现的位置,如果匹配迭代中的键(包括相同字符),则我希望打印所有基因ID。
For dictionaries you cannot have more than one of the same key. 对于字典,您不能使用多个相同的键。 Instead, I would suggest using a dictionary whose keys point to lists of values:
相反,我建议使用字典,其键指向值列表:
seq_depth = {"id": ["item1", "item2", "item3"]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.