宽客秀

宽客秀

Quant.Show的Web3站点,Archives from quant.show

In Python, using for+remove is a big pit...

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

Notes on for in Python

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

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.