Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

group consecutive numbers in list python

import more_itertools as mit


iterable = [2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 20]
[list(group) for group in mit.consecutive_groups(iterable)]
# [[2, 3, 4, 5], [12, 13, 14, 15, 16, 17], [20]]
Comment

PREVIOUS NEXT
Code Example
Python :: how to put iput python 
Python :: pandas groupby sum 
Python :: Python program to remove duplicate characters of a given string. 
Python :: Join a list of items with different types as string in Python 
Python :: dashes seaborn 
Python :: converting a string to a dictionary in python 
Python :: moving average numpy 
Python :: dynamo python templete 
Python :: decyphing vigener cypher without key 
Python :: get most repeated instance in a queryset django 
Python :: numpy get specified colums 
Python :: auto create requirements.txt 
Python :: pil to grayscale 
Python :: python export console output to file 
Python :: python make integer into a list 
Python :: python interpreter clear screen 
Python :: python get average list in 2d array 
Python :: numpy array heaviside float values to 0 or 1 
Python :: create a sequence of numbers in python 
Python :: how to move file from one location to another with python 
Python :: python run another python script 
Python :: mongodb connection using python 
Python :: grouping products for sales 
Python :: pip is not recognized as an internal or external command cmd 
Python :: python get script path 
Python :: python create tuple from input 
Python :: confusion matrix python 
Python :: pickle dump 
Python :: python expression factorisation 
Python :: create dataframe from csv and name columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =