In [38]: d = set(range(3))
In [39]: d
Out[39]: set([0, 1, 2])
In [40]: for i in d:
d -= set([2])
....:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/gridlex/workspace/HomeBackSites/nava_scripts/<ipython-input-40-b79926ab34ec> in <module>()
----> 1 for i in d:
2 d -= set([2])
3
RuntimeError: Set changed size during iteration
python中这两个赋值有什么区别?
1. d -= 集合([2])
2 d = d - 集合([2])
In [41]: d = set(range(3))
In [42]: for i in d:
d = d - set([2])
....:
In [43]: d
Out[43]: set([0, 1])