Reprint an article by Damo Canglang titled "Some pits in remove in Python" https://www.cnblogs.com/lipx9527/p/9450819.html
In fact, the official website of Python explains the reasons for the BUG, but it is written in a cumbersome manner and does not provide examples. Many people may overlook it. Damo Canglang's article is more specific. The official website reference is as follows: https://docs.python.org/3.7/reference/compound_stmts.html#the-for-statement
In addition, it is worth emphasizing the solution, which is to use deepcopy instead of simple assignment. The latter only implements object reference and cannot solve this BUG. The former establishes a new variable independently. For a more detailed explanation, you can refer to Feige Baqi's article titled "Differences between direct assignment, deepcopy, and copy in Python" https://www.cnblogs.com/feigebaqi/p/9554968.html