class Solution:
def removeDuplicates(self, nums) :
# 对列表进行循环修改时要使用nums[:]而不是nums
for n in nums:
if nums.count(n) > 1:
nums.remove(n)
return nums
s=Solution()
List=[]
Length=4
for i in range(Length):
List.append([])#初始化二维列表
List[0].append(1)
List[0].append(2)
List[1].append(1)
List[1].append(3)
List[2].append(1)
List[2].append(2)
List[3].append(1)
List[3].append(3)
print(List)
com=s.removeDuplicates(List)
print(com)
输出:
[[1, 2], [1, 3], [1, 2], [1, 3]]
[[1, 2], [1, 3]]
这种方法只能去除重复两次的元素。