Python版本: 3.4.2
代码: 全选
words = ['cat', 'window', 'defenestrate']
for w in words: # Loop over a slice copy of the entire list.
if len(w) > 6:
words.insert(0, w)
https://docs.python.org/3.4/tutorial/co ... statementsIf you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected items), it is recommended that you first make a copy. Iterating over a sequence does not implicitly make a copy. The slice notation makes this especially convenient
我试着把slice去掉了,结果就死循环?