nested lists - snake result in Python -
i'm trying obtain snake outcome (left right, top down) of set of characters in python 3. have managed using zip, following sample code:
>>> abcd = ['a','b','c','d'] >>> = iter(abcd) >>> t = zip(i,i) >>> x in t: ... print(x) ... ('a', 'b') ('c', 'd') >>> g in zip(abcd,abcd): ... print(g) ... ('a', 'a') ('b', 'b') ('c', 'c') ('d', 'd')
but i'd understand why zip(abcd,abcd) not return same result zip(i,i) ?
zip make tuples 2 list , make tuple (a,a) (b,b) (c,c) (d,d)
iter() iterate through using next() hence when using iter() function make tuple of (a,b) (c,d)
Comments
Post a Comment