 # List is continuous

Hi

If I have a simple list of lists, what is the best way to check if the lists are continuous? For example, in the image below, List  is not continuous, whereas list  is. Is this a task for Python or can it be achieved with OOTB nodes?

Thanks

Off the top of my head, try this:

(List.Drop(lst,1)-List.Drop(lst,-1)) ==1;
Then check if all true. 2 Likes

Python definition ``````import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

def sequential(list):
check = []
for i in list:
try:
if list[list.index(i)+1]==i+1:
check.append(True)
else:
check.append(False)
except:
pass
return all(check)

input = IN
output = []

for i in input:
output.append(sequential(i))

OUT = output``````
2 Likes

Just another perspective to your question. Have you considered forward sequence only? How about the reverse? say 3,2,1 is that considered as continuous as well?

I believe python by @Ewan_Opie would be the cleanest. But if purely nodes and simple code blocks then check out this option.

Sample Dyn - ListContinuousForwardBackward.dyn (39.9 KB)

Cheers,
Jowenn

2 Likes

@simoneavellini This is what I was after. Thanks.

Thanks too for the Python script @Ewan_Opie. Lots of options

@JowennLua Forward sequence only as they were indexs of elements.

2 Likes

Hello
you can also use the range function Python to compare

``````myList = IN
OUT = (myList == list(range(myList, myList[-1]+1)))``````