标签:sse 并行迭代 mat code val 判断 span 运算符 布尔
list1=[1,2,3,4,5] list2=["a","b","c","d","e"] print(list(zip(list1,list2))) # [(1, ‘a‘), (2, ‘b‘), (3, ‘c‘), (4, ‘d‘), (5, ‘e‘)]
迭代时获取索引,内置函数enumerate进行枚举化:
for index,string in enumerate(stirngs): #index返回索引,string返回内容
a=[x for x in range(10)] print(a) #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b=[x*x for x in range(10)] print(b) #[0, 1, 4, 9, 16, 25, 36, 49, 64, 81] c=[(x,y) for x in range(3) for y in range(4) if x<y] print(c) #[(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
s={i:"{} squared is {}".format(i,i**2) for i in range(4)} print(s) #{0: ‘0 squared is 0‘, 1: ‘1 squared is 1‘, 2: ‘2 squared is 4‘, 3: ‘3 squared is 9‘}
标签:sse 并行迭代 mat code val 判断 span 运算符 布尔
原文地址:https://www.cnblogs.com/i201102053/p/10618384.html