How to do quad panel divisions using python

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]])
1 Like

@harry_zhao ,

i used buildin function Zip!

a = IN[0]
b = IN[1]
c = IN[2]
d = IN[3]

OUT = zip(a,b,c,d)

it is still not python, maybe it helps

3 Likes

Thanks for your input.
… The problem is not with the approach, I just had an uneven list🤦‍♂️

1 Like

@harry_zhao ,

this outList2 ?

1 Like

No, it’s with the word sub-list, I had 9 items instead of the 10 items of the other sub-lists.
So there was a mismatch :sweat_smile:

1 Like

Don’t feel bad… Literally spent 1.5 hours fighting that same issue last week!

1 Like