This is a duplicate question, with the exception of R, not Python.
I would like to identify groups of contiguous (some call them continuous) integers in a list where duplicate entries are considered as existing within the same range. Therefore:
myfunc(c(2, 3, 4, 4, 5, 12, 13, 14, 15, 16, 17, 17, 20))
returns:
min max 2 5 12 17 20 20
Although any output format will be fine. My current brute force method, for-loop is pretty slow.
(Apologies if I could easily reformulate Python's answer, and I'm stupid!)
source share