How to create sublists each time there is a specific item in a list

hello, I am trying to find an easy way to slice or split in sublists a list every time there is a specific value, in this case every time you see true.

Like this?

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:

from itertools import groupby
OUT = [list(g) for k,g in groupby(IN[0])]
4 Likes

awesome, thanks very much

1 Like

This is very good, it will be very useful for me as well. :clap:

1 Like

how would it be with itertools if the flatten list is sliced each time there is a specific item in the list?