首页 > python双循环怎么处理?

python双循环怎么处理?

listone = [a,b,c,d]
listtwo = [1,2,3,4]

请问如何写循环,使得循环结果为[a,1],[b,2]……


这不就是zip吗


题主不用zip要用双循环?

listone = ['a', 'b', 'c', 'd']

listtwo = [1, 2, 3, 4]

listtwo_iter = iter(listtwo)

l = []
for x in listone:
    for y in listtwo_iter:
        l.append([x, y])
        break
print l

这样?


print zip(listone,listtwo)

(逃

【热门文章】
【热门文章】