mutating a deque whilst iterating over it

Cameron Simpson cs at cskk.id.au
Thu Feb 11 23:05:41 EST 2021


On 11Feb2021 20:22, duncan smith <duncan at invalid.invalid> wrote:
>      It seems that I can mutate a deque while iterating over it if I
>assign to an index, but not if I append to it. Is this the intended
>behaviour? It seems a bit inconsistent. Cheers.

I think that just means that the deque didn't _notice_ your change in 
the former case. Not necessarily that it wouldn't want to.

I confess to not being sure that appending to a deque during an 
iteration should be a bad thing, except that with a bounded deque that 
might entail discarding the element at your current iteration point.  
Maybe.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list