# Append item to a list in specific path

**URL:** <https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063>\
**Category:** Lists-Logic\
**Tags:** python\
**Created:** [October 10, 2020, 6:09pm UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063 "2020-10-10T18:09:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faruk\_B](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@Faruk\_B](https://forum.dynamobim.com/u/Faruk_B)\
**Post date:** [October 10, 2020, 6:09pm UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063/1 "2020-10-10T18:09:56Z")

</div>

Hi all,

I am having difficulty to append item to a list with Python.

I am trying to keep at output the same data structure as the input and for that I am using two for loops.

Error is saying that ( **i** ) is out of range, but when I output ( **i** ) I have list 0, 1, 2, 3 what is matching to indexes of the branches

I am quiet inexperienced with Python and I am really grateful for all your help

 ![PythonTreeQuestion.PNG](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/c/bc441e4ae4083791c9579ea7292714c9462a57e8.jpeg)

Thanks in advance

---

<div class="post-metadata">

**Author:** ![AmolShah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/amolshah/32/103244_2.png) [@AmolShah](https://forum.dynamobim.com/u/AmolShah)\
**Post date:** [October 10, 2020, 8:22pm UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063/2 "2020-10-10T20:22:56Z")

</div>

@Faruk_B I don’t think you need to use range and then use it to call the sublist.  
Instead try this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/d/1d81d4c40b5cc9e66c8d58d109f66c4044d8ee97.png)

```
wallsTrees = IN[0]
analyticalElements = []

for wallsTree in wallsTrees:
	temp = []
	for wall in wallsTree:
		a = 5
		temp.append(a)
	analyticalElements.append(temp)
	
OUT = analyticalElements
```

---

<div class="post-metadata">

**Author:** ![Faruk\_B](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@Faruk\_B](https://forum.dynamobim.com/u/Faruk_B)\
**Post date:** [October 10, 2020, 8:55pm UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063/3 "2020-10-10T20:55:48Z")

</div>

@AmolShah thanks a lot, I tried and it is working for numbers. Thing is that I am trying to get analytical elements from the walls and when I try to append _temp_ list to _ **analyticalElements** _ list I get error: **expected Element got List**

```
wallsTree = IN[0]
analyticalElements = []

for wall in wallsTree:
	temp = []
	for wall in wallsTree:
		a = Element.GetAnalyticalModel(wall)
		temp.append(a)
	
	analyticalElements.append(temp)

OUT = analyticalElements
```

---

<div class="post-metadata">

**Author:** ![AmolShah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/amolshah/32/103244_2.png) [@AmolShah](https://forum.dynamobim.com/u/AmolShah)\
**Post date:** [October 10, 2020, 11:55pm UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063/4 "2020-10-10T23:55:43Z")

</div>

@Faruk_B It is not working because you are nesting another loop with the exact same variables (i & j).

What you did is

```
for i in j:
	temp = []
	for i in j:

```

Instead of doing

```
for i in j:
	temp = []
	for k in i:

```

Here you go again:

```
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

wallsTrees = UnwrapElement(IN[0])
analyticalElements = []

for wallsTree in wallsTrees:
	temp = []
	for wall in wallsTree:
		temp.append(Element.GetAnalyticalModel(wall))
	analyticalElements.append(temp)

OUT = analyticalElements

```

I hope this time you will copy the code exactly as stated above and not get creative in renaming the variables! 😅

---

<div class="post-metadata">

**Author:** ![Faruk\_B](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@Faruk\_B](https://forum.dynamobim.com/u/Faruk_B)\
**Post date:** [October 11, 2020, 5:53am UTC](https://forum.dynamobim.com/t/append-item-to-a-list-in-specific-path/56063/5 "2020-10-11T05:53:21Z")

</div>

@AmolShah, thanks, I made it to complicated. Thank you again for your help it works perfect
