【发布时间】:2020-11-29 06:52:15
【问题描述】:
我创建了一个函数来评估列表是否有重复:
def duplica(list_to_check):
if len(set(list_to_check)) != len(list_to_check):
print('there are duplicates inside the list')
result = 0
else:
result = 1
return result
print(duplica([1, 1, 2]))
##test it:
there are duplicates inside the list
0
我想知道是否有其他方法可以使用仅一行代码(例如 lambda 或 map)来评估列表
【问题讨论】:
-
不,它不回答
-
确实如此。
标签: python