用 more_itertools.consecutive_groupsimport more_itertools as mitmy_list = [1,2,3,4,5,9,10,11,12,13,14,15]x = [list(group) for group in mit.consecutive_groups(my_list)]oputput = []for i in x: temp = [i[0],i[1],i[-2],i[-1]] output.extend(temp) 输出:[1,2,4,5,9,10,14,15]