如何在列表中找到双打?我的算法如何在列表python中找到并保留双精度值?
import collections
a = [1,2,3,4,5,2,4,5]
b = []
for x,y in collections.Counter(a).items():
if y>1:
b.append(x)
print(b) # [2, 4, 5]
c = []
for item in a:
if item in b:
c.append(item)
print(c) # [2, 4, 5, 2, 4, 5]
的版本需要找到结果如c
代码缺陷:
- 三甲之列(A,B,C),一个集合(字典)
- 长代码
我需要离开列表双打值,例如。 x = [1,2,2,2,3,4,5,6,6,7],需要[2,2,2,6,6]不是[2,6]
是的,正如c列表print(c)#[2,4,5,2,4,5] – Igor