### 一、前言

origin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]

### 二、实现过程

#### 方法一

import itertoolsorigin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]final_lst = [x[0] for x in itertools.groupby(origin_lst)]print(final_lst)

#### 方法二

origin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]res = [origin_lst[i] for i in range(len(origin_lst)) if i == 0 or origin_lst[i] != origin_lst[i - 1]]print(res)

#### 方法三

origin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]result = [origin_lst[0]]for i in range(1, len(origin_lst)):    if origin_lst[i] != origin_lst[i-1]:        result.append(origin_lst[i])print(result)

#### 方法四

origin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]def del_adjacent(iterable):    prev = object()    for item in iterable:        if item != prev:            prev = item            yield itemresult = list(del_adjacent(origin_lst))print(result)

#### 方法五

origin_lst = [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]lst_final = []for index, val in enumerate(origin_lst):    if val != origin_lst[index - 1]:        lst_final.append(val)print(lst_final)