Create sublist by value

Dear Dynamo Specialists,

Can anyone help me?
image

How to create sublists when the value is 0, so make sublist at value?

Example:


Thanks!

But it is not working.

You need to find the difference between indices to get the chop length.

Here is a Python solution:

liste = IN[0]

def create_sub(liste):
	res = []
	for i,x in enumerate(liste):
		for el in liste:
		
			if el ==0:
				index_el = liste.index(el)
				erste = liste[:index_el]
				erste.insert(0,0)
				res.append(erste)
				liste = liste[index_el+1:]
				if 0 not in liste:
					
				
					res.append(liste)
				

					
	final = res[len(res)-1].insert(0,0)		
	yield res
	
OUT = create_sub(liste)

Thanks man!!!

Nice solution!!

1 Like