I'm trying to iterate over a list of lists of lists and list of tuples at the same time, replacing certain values within the list of lists of lists with values from the list of tuples.
Here is my code so far:
tups = [(1,2,3),(4,5,6),(9,8,7)]
lsts = [[[1, 0, 1], [2, 3, 1, 0], [1, 1, 1, 1, 10, 0]], \
[[1, 0, 1], [2, 3, 1, 0], [1, 1, 1, 1, 10, 0]], \
[[1, 0, 1], [2, 3, 1, 0], [1, 1, 1, 1, 10, 0]]]
for index1, aitem in enumerate(tups):
for index2, a in enumerate(aitem):
for index3, mega_item in enumerate(lsts):
for index4, bitem in enumerate(mega_item):
for index5, b in enumerate(item):
if i == 0:
lsts[index3][index4][index5] = a
break
else:
continue
break
else:
continue
break
else:
continue
break
I want my solution to produce lsts with the 0s replaced by the values in tups in sequential order like this:
lsts = [[[1, 1, 1], [2, 3, 1, 2], [1, 1, 1, 1, 10, 3]], \
[[1, 4, 1], [2, 3, 1, 5], [1, 1, 1, 1, 10, 6]], \
[[1, 9, 1], [2, 3, 1, 8], [1, 1, 1, 1, 10, 7]]]
However, the my result at the moment is:
lsts = [[[1, 1, 1], [2, 3, 1, 2], [1, 1, 1, 1, 10, 3]], \
[[1, 1, 1], [2, 3, 1, 2], [1, 1, 1, 1, 10, 3]], \
[[1, 1, 1], [2, 3, 1, 2], [1, 1, 1, 1, 10, 3]]]
I believe my loop may only be iterating over the first item in my list of tuples.
How can I solve this problem?