# Divide list with a specific string

**URL:** <https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389>\
**Category:** Uncategorized\
**Created:** [January 22, 2024, 12:35pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389 "2024-01-22T12:35:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 22, 2024, 12:35pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/1 "2024-01-22T12:35:38Z")

</div>

Dear professionals, i am currently trying to get two lists of one which should be divided with a " - " sign.  
I am sure it would be a piece of cake for you.  
Sadly i have no idea which Node could help me to get from “Input” the “Output1” and “Output2”.

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

Please note that the indices are always the same and that the “Output2” has indices those are empty.

Thank You in advance!

---

<div class="post-metadata">

**Author:** ![Garbage\_Collector](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@Garbage\_Collector](https://forum.dynamobim.com/u/Garbage_Collector)\
**Post date:** [January 22, 2024, 12:59pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/2 "2024-01-22T12:59:45Z")

</div>

Hi!  
You can use string.split for this

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/b/cb41625686165d9993b628fccf5c83a2792ed641.png)

---

<div class="post-metadata">

**Author:** ![Garbage\_Collector](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@Garbage\_Collector](https://forum.dynamobim.com/u/Garbage_Collector)\
**Post date:** [January 22, 2024, 1:09pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/3 "2024-01-22T13:09:30Z")

</div>

I realised this was half a solution…

To keep your lists structure maybe just use this python code:

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

```auto
# Load the Python Standard and DesignScript Libraries
import sys
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.
input_list = IN[0]

list_one = []
list_two = []

for item in input_list:
    parts = item.split(" - ")
    list_one.append(parts[0] if len(parts) > 1 else item)
    list_two.append(parts[1] if len(parts) > 1 else None)

OUT = (list_one, list_two)

```

---

<div class="post-metadata">

**Author:** ![NERDASORUS](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NERDASORUS](https://forum.dynamobim.com/u/NERDASORUS)\
**Post date:** [January 22, 2024, 3:36pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/4 "2024-01-22T15:36:31Z")

</div>

This should do the trick:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/e/0e8eb5b9a5da7b5c703300df6304c3d7faf69743.png)

you can clean the nulls of the second output

---

<div class="post-metadata">

**Author:** ![Alien](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/32/40701_2.png) [@Alien](https://forum.dynamobim.com/u/Alien)\
**Post date:** [January 22, 2024, 4:22pm UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/5 "2024-01-22T16:22:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 23, 2024, 8:19am UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/6 "2024-01-23T08:19:09Z")

</div>

Wow. It worked.  
Thank You I’ve learned a lot!

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 23, 2024, 8:21am UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/7 "2024-01-23T08:21:02Z")

</div>

Hi, Thanks a lot, It works also perfecty!  
Sadly I can mark only one solution and Python is always more elegant:)  
Still I’ve learned from You a lot!

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 23, 2024, 8:22am UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/8 "2024-01-23T08:22:34Z")

</div>

Thank You!  
Sadly i have problem with an archilab package.  
I’ve used ReplaceByCondition instead.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/5/35262a95e4183a0ea1eebfc085b973062feb4bcc.png)

---

<div class="post-metadata">

**Author:** ![Garbage\_Collector](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@Garbage\_Collector](https://forum.dynamobim.com/u/Garbage_Collector)\
**Post date:** [January 23, 2024, 8:56am UTC](https://forum.dynamobim.com/t/divide-list-with-a-specific-string/97389/9 "2024-01-23T08:56:06Z")

</div>

Hey!

I didnt realise you needed empty strings instead of nulls 🙂

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4c539c30db73e68373200f9e608b3520901a9d8f.png)  
I changed the python code so you dont need those extra replace nodes

```auto
# Load the Python Standard and DesignScript Libraries
import sys
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.
input_list = IN[0]

list_one = []
list_two = []

for item in input_list:
    parts = item.split(" - ")
    list_one.append(parts[0] if len(parts) > 1 else item)
    list_two.append(parts[1] if len(parts) > 1 else "")

OUT = (list_one, list_two)

```
