Editing a list of strings with python

I’m trying to edit a list of strings with a python script. It works in python but not in dynamo.

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.
dataEnteringNode = IN

# Place your code below this line

oldlist = IN[0]
newfamilylist=[]

def returnfamily_string(family):
    x = "Family:"
    if x in family:
            string1 = family.split(x, 1)[1]
            return(string1.split(" ", 1)[1])
            
for y in oldlist:
    newfamilylist.append(returnfamily_string(y))

          
# Assign your output to the OUT variable.
OUT = newfamilylist

@Harald ,

i had here a similar topic

spliting by “.rvt” answered someone

KR

Andreas

Sorry, I don’t quite understand. How would I need to edit my code?

@Harald ,

like this ?

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
elems = IN[0]
lists = []

for i in elems:
	rvtFileName = i.Name.split(":")[0]
	lists.append([i,rvtFileName])

OUT = lists

1 Like

Hello,
It is possible that I am off the mark on your expectations.

oldlist2=[]

for i in IN[0]:
    oldlist2.append(str(i))
newfamilylist=[]

def returnfamily_string(family):
    x = "Family:"
    if x in family:
            string1 = family.split(x, 1)[1]
            return(string1.split(" ", 1)[1])
            
for y in oldlist2:
    newfamilylist.append(returnfamily_string(y))

          
# Assign your output to the OUT variable.
OUT = newfamilylist

Cordially
christian.stan

1 Like

Yeah this works. I was not aware I had to manipulate the input list first.

Thank you.

1 Like

you can also do it in the loop

for y in oldlist:
        newfamilylist.append(returnfamily_string(str(y)))

Cordially
christian.stan

Thanks.

1 Like