擅长:python、mysql、java
<p>每次迭代都会覆盖列表。相反,如果不创建新的键列表,您可以检查dict中是否存在该键</p>
<p><strong>例如:</strong></p>
<pre><code>image_dict={}
for index, item in enumerate(data.ImageID):
if item not in image_dict:
image_dict[item] = []
image_dict[item].append((data.XMax[index], data.XMin[index], data.YMax[index], data.YMin[index]))
</code></pre>