python 判断列表最大连续值

from itertools import groupby

lst = [1, 2, 3, 5, 6, 7, 8, 11, 12, 13, 19]    # 连续数字

continuity_list = []

fun = lambda x: x[1]-x[0]
for k, g in groupby(enumerate(lst), fun):
    l1 = [j for i, j in g]    # 连续数字的列表
    continuity_list.append(len(l1))

max_continuity = max(continuity_list)

你可能感兴趣的:(python 判断列表最大连续值)