标签:enumerate
有个列表t, 去掉偶数位的值
t = [5, 6, 7, 8, 9, 10, 11, 12, 13]
for i, v in enumerate(t):
if i % 2 == 0:
t.remove(v)
print t # 请问t是什么
In [1]: t = [5, 6, 7, 8, 9, 10, 11, 12, 13]
In [2]: for i,v in enumerate(t):
...: print "t = %s" % t
...: print "(i,v) = (%d, %d)" % (i,v)
...: if i % 2 == 0:
...: t.remove(v)
...: print "new_t = %s" % t
...: print "del the value is %d" % v
...: print "================================="
...: print "the result of t = %s" % t
t = [5, 6, 7, 8, 9, 10, 11, 12, 13]
(i,v) = (0, 5)
new_t = [6, 7, 8, 9, 10, 11, 12, 13]
del the value is 5
=================================
t = [6, 7, 8, 9, 10, 11, 12, 13]
(i,v) = (1, 7)
new_t = [6, 7, 8, 9, 10, 11, 12, 13]
del the value is 7
=================================
t = [6, 7, 8, 9, 10, 11, 12, 13]
(i,v) = (2, 8)
new_t = [6, 7, 9, 10, 11, 12, 13]
del the value is 8
=================================
t = [6, 7, 9, 10, 11, 12, 13]
(i,v) = (3, 10)
new_t = [6, 7, 9, 10, 11, 12, 13]
del the value is 10
=================================
t = [6, 7, 9, 10, 11, 12, 13]
(i,v) = (4, 11)
new_t = [6, 7, 9, 10, 12, 13]
del the value is 11
=================================
t = [6, 7, 9, 10, 12, 13]
(i,v) = (5, 13)
new_t = [6, 7, 9, 10, 12, 13]
del the value is 13
=================================
the result of t = [6, 7, 9, 10, 12, 13]
本文出自 “Linux_Config” 博客,请务必保留此出处http://liang1026.blog.51cto.com/10119067/1681678
标签:enumerate
原文地址:http://liang1026.blog.51cto.com/10119067/1681678