 # Code Block or Python Reduce the Numbers in a List By Roundup with a Range

Hi, trying to reduce the numbers in a list By Roundup with a Range of 30.

Like this ? Hi, Thank you for the fast reply, but is has to do with min. and max. number in the list.

So for your example, the difference form min. and max. number in the list must be smaller than 30.

0 to 15 = smaller than 30
15 to 22 = smaller than 30 | 0 to 22 = smaller than 30

22 to 31 = smaller than 30 | 0 to 31 = bigger than 30 ## So 0, 15, 22 is a group

31 to 66 = bigger than 30 ## So 31 is a new group

66 to 78 = smaller than 30

78 to 95 = smaller than 30 | 66 to 95 = smaller than 30
95 to 103 = smaller than 30 | 66 to 103 = bigger than 30 ## So 66, 78, 95 is a group

Last is 103 | ## group I see. Like this then ? Note : you might want to sort the input before using the Python Script.  Python Script :

``````input = IN
rng = IN

result = []
visited = []
for i in range(len(input)):
if(input[i] in visited):
continue;
sub_result = [input[i]];
for j in range(i+1,len(input)):
if(abs(input[j]-input[i]) <= rng):
visited.append(input[j]);
sub_result.append(input[j]);
result.append(sub_result);
OUT = result;``````
1 Like
1 Like