Divide list with a specific string

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”.

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

Thank You in advance!

Hi!
You can use string.split for this

I realised this was half a solution…

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

# 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)
1 Like

This should do the trick:

you can clean the nulls of the second output

2 Likes

2 Likes

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

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!

1 Like

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

Hey!

I didnt realise you needed empty strings instead of nulls :slight_smile:


I changed the python code so you dont need those extra replace nodes

# 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)
1 Like