from itertools import groupby
from operator import itemgetter
c_list = [[1,2,1], [4,6,8], [3,4,1]]
gen_groups = (list(g) for _, g in groupby(sorted(c_list, key=itemgetter(2)), key=itemgetter(2)))
res = [g if len(g) > 1 else g[0] for g in gen_groups]
print(res)
1条答案
按热度按时间fwzugrvs1#
按以下方式应用
itertools.groupby
: