我有三个列表:
gene = [gene_1, gene_2]
number = [1, 2]
list_third = ['atcatcg', 'atcatcg']
我想创建一个字典,并且我希望该字典的键为包含第一个列表和第二个列表的元素(基因和数字)的元组,并且值将为序列
我希望输出为:
dict = {(gene_1, 1):'atcatcg', (gene_2, 2):'atcatcg'}
答案 0 :(得分:8)
两次使用dict
构造函数和zip
...:
>>> dict(zip(zip(gene, number), list_third))
{('gene_2', 2): 'atcatcg', ('gene_1', 1): 'atcatcg'}
答案 1 :(得分:7)
使用zip:
plot_trisurf
或者,作为替代:
gene = ['gene_1', 'gene_2']
number = [1, 2]
list_third = ['atcatcg', 'atcatcg']
result = {tuple(key) : value for *key, value in zip(gene, number, list_third)}
print(result)
答案 2 :(得分:1)
zip
遍历三个列表
gene
and number
作为键,并使用序列作为值。