擅长:python、mysql、java
<p>@JackRandall,他们发现你最后一本字典的语法不正确。我建议你读一读<a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow">https://docs.python.org/2/tutorial/datastructures.html#dictionaries</a>,了解一下字典。你可能希望你的最终词典看起来像这样:</p>
<pre><code>Final = {'0':[[1, 5, 3], [3, 6, 6], [4, 9, 8], [5, 2, 9]], '.001':[[2, 2, 3].....]}
</code></pre>
<p>开始时,您可以在X中循环遍历键,然后使用Y和Z的键访问元素,并将它们全部附加到Final['key']的数组中。这应该让你开始,我可以回答更多的问题。你知道吗</p>
<p><strong>这是根据您的评论更新的:
如果键在X中不存在,它将不插入任何键</p>
<pre><code>X = {'0':[1, 3, 4, 5], '.001':[2, 4, 6, 7], 'XonlyKey':[1,1,1,1,]}
Y = {'0':[5, 6, 9, 2], '.001':[2, 6, 8, 4]}
Z = {'0':[3, 6, 8, 9], '.001':[3, 1, 5, 8]}
Final={}
for key, value in X.iteritems():
tempArray=[value]
for tempDict in (Y,Z):
if key in tempDict:
tempArray.append(tempDict[key])
else:
tempArray.append(None)
Final[key]=tempArray
</code></pre>