标签:pytho clu code python zip index clust class 循环
循环
range实现循环
S = [1, 2, 3, 4, 5, 6]
for i in range(0, len(S), 2):
print S[i]
enumerate 实现循环
S = [10, 20, 30]
for (index, value) in enumerate(S):
print index
print value
zip
ta = [1, 2, 3, 4]
tb = [9, 8, 7]
tc = ['a', 'b', 'c']
for (a, b, c) in zip(ta, tb, tc):
print(a, b, c)
'''
(1, 9, 'a')
(2, 8, 'b')
(3, 7, 'c')
'''
ta = [1, 2, 3]
tb = [9, 8, 7]
# cluster
zipped = zip(ta, tb)
print(zipped)
# decompose
na, nb = zip(*zipped)
print(na, nb)
'''
[(1, 9), (2, 8), (3, 7)]
((1, 2, 3), (9, 8, 7))
'''
标签:pytho clu code python zip index clust class 循环
原文地址:https://www.cnblogs.com/jiqing9006/p/10604668.html