>>> for x in a[:]: # make a slice copy of the entire list
... if len(x) > 6: a.insert(0, x)
...
>>> a
[’defenestrate’, ’cat’, ’window’, ’defenestrate’]
帮我解释解释什么意思。。看不懂了
>>> for x in a[:]: # make a slice copy of the entire list
... if len(x) > 6: a.insert(0, x)
...
>>> a
[’defenestrate’, ’cat’, ’window’, ’defenestrate’]
帮我解释解释什么意思。。看不懂了
>>> # Measure some strings: ... a = [’cat’, ’window’, ’defenestrate’] >>> for x in a: ... print x, len(x)
#这里输出的就是:
'cat' 3
'window' 6
'defenestrate' 12
>>> for x in a[:]: # make a slice copy of the entire list ... if len(x) > 6: a.insert(0, x) ...#这里判断如果x的长度大于6,就插在第一个位置,0就是第一个元素,只有defenestrate的长度大于6,所以就将defenestrate插入在第一位置 >>> a [’defenestrate’, ’cat’, ’window’, ’defenestrate’]