Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find continuous ranges in a list of integers
ResourceFunction["FindRanges"][list] returns ranges of consecutive values for the integers in list. |
Find ranges of consecutive values in a list of integers:
In[1]:= |
Out[1]= |
The given list does not need to be sorted, but will be sorted automatically:
In[2]:= |
Out[2]= |
The returned ranges can be joined into the original set of numbers again:
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Noninteger numbers are "swallowed" if they are between consecutive integers in the list:
In[7]:= |
Out[7]= |
Expressions that are not integers or real numbers each constitute their own "range":
In[8]:= |
Out[8]= |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License