HI ALL
I have a list that I want to divide to get a list as in the pictures
Please Help
Thanks in advance

primitive list

Divide them into lists based on the code

Like this?
[image]
DesignScript:
sublsts = DSCore .List.Sublists(x,0..1,1);
first_itm = DSCore.List.FirstItem(sublsts<1>);
pairs = sublsts == first_itm;
bools = DSCore.List.AllTrue(pairs<1>)? false: DSCore.List.AllFalse(pairs<1>)?
false:true;
positions = DSCore.List.Flatten([0,DSCore.List.AllIndicesOf(bools,true)+1,
DSCore.List.Count(bools)],-1);
lengths = DSCore.List.RestOfItems(positions)-DSCore.List.DropItems(positions,-1);
out = DSCore.List.Chop(y,lengths);
Python:
f…
```
from itertools import groupby
OUT = [list(g) for k,g in groupby(IN[0])]
```

I want to get to this list

q4 split in sublists a list every time 1.dyn (14.4 KB)

Kind regards,
ALAA

If I understood correctly, the empty lists in your data are essentially the separator. You can try this:

```
from itertools import groupby
def flatten(lst):
for i in lst:
if not i: yield []
elif isinstance(i, list):
for j in i: yield j
else: yield i
OUT = [list(g) for k, g in groupby(flatten(IN[0]), key=lambda x: not x) if not k]
```

2 Likes