-
富国沪深
有一Counter堂课可以解决collections这个问题from collections import Counterlst = [4,3,2,4,5,6,4,7,6,8]d = Counter(lst) # -> Counter({4: 3, 6: 2, 3: 1, 2: 1, 5: 1, 7: 1, 8: 1})res = [k for k, v in d.items() if v > 1]print(res)# [4, 6]
-
拉风的咖菲猫
简单回答:>>> l = [1,2,3,4,4,5,5,6,1]>>> set([x for x in l if l.count(x) > 1])set([1, 4, 5])
-
炎炎设计
使用简单的内置功能,您可以:>>> a=[4,3,2,4,5,6,4,7,6,8]>>> b=[a[i] for i in range(len(a)) if a[i] in a[:i]][1:]>>> b[4, 6]