Flatten list in python

Hi,

Can you help me? what is wrong?

Change line 5:

list1 = [0]

into

list1 = IN[0]

(oh btw: you can use list.join to do the same.)

1 Like

The most efficient way I’ve found is to use:

from itertools import chain
lst1 = IN[0]
newlist = list(chain.from_iterable(lst1))
OUT = newlist

EDIT: I’ve verified that this works with Ironpython. image

2 Likes

The question was why his script wasn’t working (he just missed the “IN”-part) … but I must say: good suggestion (saves some loops :slight_smile: ) @Jonathan.Olesen.:+1::+1:

The most efficient way was to just use list.join??

1 Like

True @3Pinter :wink:

Depending on the use and intention of the final graph/script and if the import needs to go into python for processing before being flattened I agree that List.Join is the most elegant solution avoiding the need for Python all together.