python3-cookbook icon indicating copy to clipboard operation
python3-cookbook copied to clipboard

1.3 中关于 deque 的描述有问题

Open pengfexue2 opened this issue 4 years ago • 1 comments

1.3 保留最后 N 个元素,讨论部分关于 deque 描述内容:

“使用 deque(maxlen=N) 构造函数会新建一个固定大小的队列。当新的元素加入并且这个队列已满的时候, 最老的元素会自动被移除掉。”

这里“最老的元素”描述有误,比如在固定长度、且 deque 元素满了时,通过 appendleft() 加入新元素后,被移除掉的是队列最右侧的元素;append() 在右侧加入新元素时,移除的是最左侧元素。用“最老的元素”可能会误以为是按加入的先后顺序来移除,产生误会。

On a deque object with fixed length when an element is added at the left side, an element is removed at the right side.

pengfexue2 avatar Jun 08 '20 09:06 pengfexue2

@pengfexue2 表达确实不太准确,但原文如此

Using deque(maxlen=N) creates a fixed-sized queue. When new items are added and the queue is full, the oldest item is automatically removed.

zlu27 avatar Feb 20 '21 05:02 zlu27