Answer the question
In order to leave comments, you need to log in
Formation of lists nested in a list from other lists according to certain rules?
Good afternoon,
there are three lists
allIndex_A = [1, 2, 8, 12, 17, 21, 23, 29]
allIndex_B = [3, 5, 7, 9, 11, 13, 15, 18, 20, 22, 24, 26, 28, 30]
allIndex_C = [4, 6, 10, 14, 16, 19, 25, 27]
newList = [[1,3,4], [2,3,4], [8,9,10], [12,13,14], ...]
Answer the question
In order to leave comments, you need to log in
allIndex_A = [1, 2, 8, 12, 17, 21, 23, 29]
allIndex_B = [3, 5, 7, 9, 11, 13, 15, 18, 20, 22, 24, 26, 28, 30]
allIndex_C = [4, 6, 10, 14, 16, 19, 25, 27]
ita, itb, itc = iter(allIndex_A), iter(allIndex_B), iter(allIndex_C)
b = c = allIndex_A[0]
newList = []
try:
while True:
a = next(ita)
while b <= a:
b = next(itb)
while c <= a:
c = next(itc)
newList.append([a, b, c])
except StopIteration:
print(newList)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question