Get Item At Index they depended a list

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

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

very thank you

Kind regards,
ALAA

1 Like