, , - .
,
x = [1,2,3,4,6,7,8,9,10,11,12,14,15,17,18,19,20,21,22,23,24,25,28,30,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]
We will denote data Trueif they are “continuous” for at least 5 members.
To do this, first get a list of differences and assign 1if the difference is 1, or assign 0, if not. This is done using y = [int(round(1/(x[i]-x[i-1]))) for i in range(1, len(x))].
After that, we get an index where the difference is assigned 0, and use it to check your status.
Full code:
import copy
x = [1,2,3,4,6,7,8,9,10,11,12,14,15,17,18,19,20,21,22,23,24,25,28,30,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]
y = [int(round(1/(x[i]-x[i-1]))) for i in range(1, len(x))]
z = copy.deepcopy(y);
zeros_check = [abs(y[i]-1)*i for i in range(0,len(y))];
zeros_id = list(set(zeros_check));
zeros_id.remove(0);
zeros_id.append(len(y));
idx = 0;
for i in zeros_id:
if sum(y[idx+1:i])>=5:
z[idx+1:i] = [True for i in range(idx,idx+i-1)];
else:
z[idx:i+1] = [False for i in range(idx,idx+i+1)];
idx = i;
for i,j,k in zip(x,y,z):
print(i,j,k)
Exit:
1 1 False
2 1 False
3 1 False
4 0 False
6 1 True
7 1 True
8 1 True
9 1 True
10 1 True
11 1 True
12 0 False
14 1 False
15 0 False
17 1 True
18 1 True
19 1 True
20 1 True
21 1 True
22 1 True
23 1 True
24 1 True
25 0 False
28 0 False
30 0 False
32 0 False
34 1 True
35 1 True
36 1 True
37 1 True
38 1 True
39 1 True
40 1 True
41 1 True
42 1 True
43 1 True
44 1 True
45 1 True
46 1 True
47 1 True
48 1 True
49 1 True