# Multiple tier list loop

Hi guys, sorry if this sounds a little convoluted, I’m trying to use multi-layered list loop,

To turn this:

[[1, 11, 111, 1111], [2, 22, 222, 2222], [3, 33, 333, 3333], [4, 44, 444, 4444], [5, 55, 555, 5555], [6, 66 , 666, 6666]];

into this:

[[1,11,1111], [11,111,1111], [2,22,2222], [22, 222,2222]…[6,66,6666], [66, 666, 6666]]

Basically taking the original 6 list of 4 items, and rearranging them in a specific order into a 12 list of 3 items each

This is the same logic one would use when turning a quad point division into a triangle division, I want to learn how to do it in Python

Here’s my attempt:

``````# Load the Python Standard and DesignScript Libraries
import sys
import clr
from Autodesk.DesignScript.Geometry import *
from operator import *

# The inputs to this node will be stored as a list in the IN variables.
listA = IN[0]

# Place your code below this line
overallList = []
for i in range(5):
sublist1 = []
sublist2 = []
sublist3 = []
sublist4 = []
sublist5 = []
sublist6 = []
for i2 in range(1):
sublist1.append(listA[i2][0])
sublist1.append(listA[i2][1])
sublist1.append(listA[i2][3])

sublist2.append(listA[i2][1])
sublist2.append(listA[i2][2])
sublist2.append(listA[i2][3])

for i2 in range(1,2):
sublist3.append(listA[i2][0])
sublist3.append(listA[i2][1])
sublist3.append(listA[i2][3])

sublist4.append(listA[i2][1])
sublist4.append(listA[i2][2])
sublist4.append(listA[i2][3])

for i2 in range(2,3):
sublist5.append(listA[i2][0])
sublist5.append(listA[i2][1])
sublist5.append(listA[i2][3])

sublist6.append(listA[i2][1])
sublist6.append(listA[i2][2])
sublist6.append(listA[i2][3])

overallList.append(sublist1)
overallList.append(sublist2)
overallList.append(sublist3)
overallList.append(sublist4)
overallList.append(sublist5)
overallList.append(sublist6)
# Assign your output to the OUT variable.
OUT = overallList
``````

There has to be a easier and more elegant solution than what I have.

One for loop and some list slicing should do the trick. Haven’t tested this myself, just typed it out on my phone, but you can give it a go:

``````OrigList = IN[0]
NewList = []
For lst in OrigList:
NewList.append(lst[0:2])
NewList.append(lst[1:3])
OUT = NewList
``````
2 Likes

very close but not quite.

The indices chosen are not sequential, it’s [0,1,3] and [1,2,3]
So it works for the second set, but not the first

So I’m wondering is there some syntax I need to use to pick out specific item from a list 2 layers below?

like List[2][4] works for singular items but not multiple.

Ah. Try swapping in `NewList.append([lst[0],lst[1],lst[3]])` then.

2 Likes

YES it works, thank you

1 Like

A Design Script alternative

`List.Flatten(List.RemoveItemAtIndex(a<1>,[2,0]<2><1>),1);`

5 Likes