Iterator Of List Of List Of Iterables
I would like to iterate of a list of list of Iterables in Python3. Stated differently, I have a matrix of iterables and I would like to loop through and get at each iteration a mat
Solution 1:
Obviously you can zip the iterators in each sublist together, you're just missing how to zip the resulting iterators together. I would unpack a generator expression:
for t in zip(*(zip(*l) for l in a)):
print(t)
((1, 11, 21), (101, 111, 121))
((2, 12, 22), (102, 112, 122))
...
Solution 2:
Why not just use indexes?
for i in range(len(a[0][0])):
tupA = (a[0][0][i], a[0][1][i], a[0][2][i])
tupB = (a[1][0][i], a[1][1][i], a[1][2][i])
print((tupA, tupB))
EDIT: this is a simple way - the way I ( a simpleton ) would do it. zip will be much more elegant and effective.
Post a Comment for "Iterator Of List Of List Of Iterables"