from itertools import groupby #获取列表中连续数字序列 lst = [234,55,233,1, 2, 3,4, 5, 6, 7, 8, 11, 12, 13, 19,21344,4646,22,34,55] # 连续数字 index_with_fault = [] fun = lambda x: x[1]-x[0] for k, g in groupby(enumerate(lst), fun): l1 = [j for i, j in g ] # 连续数字的列表 if len(l1)>6:#时间连续的点超过6个也就是连续时间超过50分钟了 index_with_fault = index_with_fault + l1 print(index_with_fault)
获取列表中连续数字序列 python
最新推荐文章于 2022-10-24 23:56:40 发布