Appending value to deque (value in dict) 将其附加到字典中的所有双端队列? [重复]

问题描述 投票:0回答:0

我有一本 deques 字典,例如,

a = {1,2,3,4,5}
dqs_dict = dict.fromkeys(a, collections.deque())

假设我想将一些值附加到与键 1 关联的双端队列。

所以我想我们可以做

value = 5
dqs_dict[1].append(value)

但这最终会将

value
附加到与每个键关联的双端队列。为什么会有这种行为?

python dictionary deque
© www.soinside.com 2019 - 2024. All rights reserved.