Answers for "find consecutive numbers in python"

1

count consecutive values in python

>>> from itertools import groupby
>>> def groups(l):
...     return [sum(g) for i, g in groupby(l) if i == 1]
...
>>> groups([0,1,0,0,0])
[1]
>>> groups([0,0,1,1,0])
[2]
>>> groups([1,1,0,1,1])
[2, 2]
Posted by: Guest on February-28-2021
0

python consecutive numbers difference between

[y-x for x, y in zip(A[:-1], A[1:])] 

>>> A = [1, 10, 100, 50, 40]
>>> [y-x for x, y in zip(A[:-1], A[1:])]
[9, 90, -50, -10]
Posted by: Guest on September-09-2020

Code answers related to "find consecutive numbers in python"

Python Answers by Framework

Browse Popular Code Answers by Language