Hi, How can I group in sublists equal values in sequence.
I would like to split my list like this:
I have more sequences of true and false bellow.
Hi, How can I group in sublists equal values in sequence.
I would like to split my list like this:
I have more sequences of true and false bellow.
You can use the groupby function from the itertools module like this:
from itertools import groupby
data = IN[0]
OUT = [list(g) for k, g in groupby(data)]
Something like that? Here’s the python for it:
data = IN[0]
OUT = []
new = []
for i,d in enumerate(data):
if i == 0:
new.append(d)
continue
if d == data[i-1]:
new.append(d)
continue
else:
OUT.append(new)
new = [d]
continue
OUT.append(new)
I think this would be hard to do with nodes without using imperative coding.
@cgartland beat me to it but this way doesn’t use imports.
Likely.
Though with only booleans you could test if the index is true && if the previous index isn’t true (shifting indices might help here), and then filter the original index numbers by those values, finally feeding the original list to a List.Chop node and chopping at the value.
Certainly a case where Python is easier.