Hi guys, I’m trying to create a 2 dimensional list from listA, by rearranging the items into sub-lists of 4 items
like [[1, a, b, 2], [2, b, c, 3], [3, c, d, 4]…[a, apple, banana, b]]
Problem occurs when I try to get the item “listA[ind+1][ind1+1]”
with this error
IndexError: list index out of range
So, is my approach wrong? is there another way to do this?
listA = [[0,1,2,3,4,5,6,7,8,9],["a","b","c","d","e","f",'g',"h","i","j"],["apple","banana","car","duck","egg","fun","go","ha","in","jam"]]
outList=[]
for ind, item in enumerate(listA):
if ind<len(listA)-1:
outList2=[]
for ind1, item1 in enumerate(item):
if ind1<len(item)-1:
outList.append([item[ind1], listA[ind+1][ind1], listA[ind+1][ind1+1]])