Python iterator when underlying object changes

前端 未结 3 1389
-上瘾入骨i
-上瘾入骨i 2021-01-20 11:37

I would like to know what\'s the general behaviour of an iterator if the underlaying object changes during the iteration.

Using a simple mutable list, it seems obvi

3条回答
  •  春和景丽
    2021-01-20 12:10

    There are some iterators that can yield more data even after a StopIteration has been raised; such iterators are considered broken.

    This does not mean the iterator is at fault -- it means that if you use such an iterator without caution you can end up with bugs and broken code.

提交回复
热议问题