+ 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])

28th Apr 2018, 3:39 PM
moamen
moamen - avatar
4 Respostas
+ 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.
28th Apr 2018, 4:16 PM
Maninder $ingh
Maninder $ingh - avatar
+ 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.
28th Apr 2018, 5:19 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
wow you're so brilliant chaotic
28th Apr 2018, 5:20 PM
moamen
moamen - avatar
0
thanks alot Maninder
28th Apr 2018, 4:20 PM
moamen
moamen - avatar