Python: 别在迭代容器 list/dict 时候增减容器内的元素

别在迭代容器 list/dict 时候增减容器内的元素:

Python 3.5.0
>>> aa = [1, 2, 3, 4, 5, 6]
>>> for a in aa:
>>>     if 2 < a < 5:
>>>         aa.remove(a)
>>> aa
[1, 2, 4, 5, 6]

反面参考来源:

http://www.oschina.net/translate/playing-around-with-await-async-in-python-3-5

http://benno.id.au/blog/2015/05/25/await1

Comments

Comment is disabled by administrator.