Zip lists in Python

前端 未结 10 2102
无人及你
无人及你 2020-11-22 02:09

I am trying to learn how to \"zip\" lists. To this end, I have a program, where at a particular point, I do the following:

x1, x2, x3 = stuff.calculations(wi         


        
10条回答
  •  臣服心动
    2020-11-22 02:43

    I don't think zip returns a list. zip returns a generator. You have got to do list(zip(a, b)) to get a list of tuples.

    x = [1, 2, 3]
    y = [4, 5, 6]
    zipped = zip(x, y)
    list(zipped)
    

提交回复
热议问题