我有一个大型的二维列表,其中某些子列表中有重复项。我只想返回重复项。例如,
Df =[[2,3,5,20],[5,10,20,10],[4,13,15,15,17,34,17],[33,34,15,21]]
我想要这样的结果。如果可以的话
Result = [[5,10,10,20],[4,13,15,15,17,17,34]]
def contains_duplicates(x):
return len(x) != len(set(x))
assert contains_duplicates([1, 2, 3]) is False
assert contains_duplicates([1, 2, 2]) is True
result = [x for x in Df if contains_duplicates(x)]
print(result)
输出:
[[5, 10, 20, 10], [4, 13, 15, 15, 17, 34, 17]]