具体代码如下:
def fn(list):
s = set()
lenth = len(list)
for i in range(lenth):
# 添加到set集合中
s.add(list[i])
# 判断是否重复元素,因重复元素,set集合不会添加,导致set集合长度和添加的元素个数不一致
if len(s) != (i + 1):
return True
else:
return False
print(fn([1,2,3,4,2]))
运行结果为:
具体代码如下:
def fn(list):
s = set()
lenth = len(list)
for i in range(lenth):
# 添加到set集合中
s.add(list[i])
# 判断是否重复元素,因重复元素,set集合不会添加,导致set集合长度和添加的元素个数不一致
if len(s) != (i + 1):
return True
else:
return False
print(fn([1,2,3,4,2]))
运行结果为: