擅长:python、mysql、java
<p>签出<a href="https://docs.python.org/3.7/library/collections.html#collections.defaultdict" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>from collections import defaultdict
image_dict = defaultdict(list)
for index, item in enumerate(data.ImageID):
image_dict[item].append((data.XMax[index], data.XMin[index], data.YMax[index], data.YMin[index]))
</code></pre>
<p>如果不存在空列表,它将创建一个空列表并附加到该列表。参见文档中的<a href="https://docs.python.org/3.7/library/collections.html#defaultdict-examples" rel="nofollow noreferrer">example</a></p>