+ 1
zip
please, any body can help me with zip or explain me this code *x, y=[1, 2],[3,4],[5,6] print (list (zip(*x+[y])) [1][1])
4 Réponses
+ 4
zip is a function which combine 2 or 2 more lists or tuples. e.g=
x=[1,2,3,4]
y=[5,6,7,8]
print(list(zip(x,y)))
#output=[(1,5),(2,6),(3,7),(4,8)]
you can combine list with tuple using zip.
zip gives you a simple matrix.
in your code.
x=[1,2],[3,4] and y=[5,6]
now zip combine it.
+ 3
x would actually equal [[1,2],[3,4]]
*x would equal [1,2] [3,4]
x+[y] would be equal to [[1,2],[3,4],[5,6]]
Which when then unpacked would [1,2] [3,4] [5,6]
when zipped together:
[(1,3,5),(2,4,6)]
Then you get [1][1] which is 4.
+ 1
wow you're so brilliant chaotic
0
thanks alot Maninder