标签: python list indexing list-comprehension
可以使用列表推导而不是以下循环吗?
a = [1,3,4,7,8,10] b = [1,1,0,0,0,1] c=[] for ii in range(len(b)): if b[ii] == 1: c.append(a[ii])
答案 0 :(得分:0)
a = [1,3,4,7,8,10] b = [1,1,0,0,0,1] print([a[ii] for ii in range(len(b)) if b[ii] == 1])