擅长:python、mysql、java
<p>这只是为了理解:</p>
<p>字典键应该是不可变的。在这个问题中,<code>[1,2,5]</code>是一个列表,它是<em>可变的</em>(可以使用append、pop、push等方法修改内容)数据类型。因此,将列表的全部内容用作字典键(非常罕见)的唯一方法是将其转换为不可变的数据类型,如<code>tuple</code>或<code>string</code>:</p>
<pre><code>new_dict = {} #initialize empty dictionary
dst = t['index'][0]['dst'] #[1,2,5]
value = t['index'][0]['value'] #[0]
new_dict[tuple(dst)] = value #new_dict key "dst" as tuple
print(new_dict)
->{(1, 2, 5): [0]}
new_dict[str(dst)] = value #new_dict key "dst" as string
print(new_dict)
>{'[1, 2, 5]': [0]}
</code></pre>