# Python Script, Controlling List Structure Output

**URL:** <https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472>\
**Category:** Revit\
**Created:** [November 15, 2018, 3:02am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472 "2018-11-15T03:02:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![austin.guter](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@austin.guter](https://forum.dynamobim.com/u/austin.guter)\
**Post date:** [November 15, 2018, 3:02am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/1 "2018-11-15T03:02:26Z")

</div>

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

In my example shown below:

 ![dynamo%20script](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/9/19ddb4fec21608fcd5c698065e4c686a1c725fe5.png)  
 ![python%20image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/4/64298049a6f0060b27ecb75a416ef646a36ae50f.png)

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?

---

<div class="post-metadata">

**Author:** ![austin.guter](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@austin.guter](https://forum.dynamobim.com/u/austin.guter)\
**Post date:** [November 15, 2018, 3:07am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/2 "2018-11-15T03:07:02Z")

</div>

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

 ![python%20image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/c/9c5cc39fa6cd9dc205cb9314d5ffe017e085c9c8.png)  
now pulling the correct data 😀, question still remains though

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [November 15, 2018, 3:25am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/3 "2018-11-15T03:25:31Z")

</div>

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

> [@austin.guter](#):
>
> I would love to be able to have (2) lists created, with (4) points in each sublist

Is this what you mean?

 ![oddevencombine](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/4/a4a08d3af55f5317d2e542913c23b8e23e48f2df.png)

---

<div class="post-metadata">

**Author:** ![austin.guter](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@austin.guter](https://forum.dynamobim.com/u/austin.guter)\
**Post date:** [November 15, 2018, 3:35am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/4 "2018-11-15T03:35:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [November 15, 2018, 3:51am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/5 "2018-11-15T03:51:12Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [November 15, 2018, 3:57am UTC](https://forum.dynamobim.com/t/python-script-controlling-list-structure-output/28472/6 "2018-11-15T03:57:25Z")

</div>

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
```
