Python Script, Controlling List Structure Output

I am trying to understand how to write data to lists using python code.

In my example shown below:


I would love to be able to have (2) lists created, with (4) points in each sublist (current output has data structured within too many list levels). I know I could easily utilize the flatten command using levels, but there has to be a way to do this in the python script as well, right?

let’s also ignore the fact that I am pulling the wrong indices:


now pulling the correct data :grinning:, question still remains though

It is hard to tell what the input list structure is like and what you want the output structure to be.

Is this what you mean?

That is what I desired. Sorry away from the computer now for the night or else I would give a better screen shot.

It’s not the most elegant or pythonic way but it works:

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

for i,v in enumerate(mList): #Add the odds onto the evens
	if i % 2 == 0:
		pass
	else:
		for sv in v:
			mList[i-1].append(sv)

ind = range(1,len(mList),2)
ind.reverse()
for i in ind: #Delete the odds using .pop()
	mList.pop(i)


OUT = mList

Alternatively, shorter version:

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
mList = IN[0]
ind = range(1,len(mList),2)
ind.reverse()

for i in ind:
	temp = mList.pop(i)
	for v in temp:
		mList[i-1].append(v)

OUT = mList
2 Likes