Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. #下面的方法可以检查给定列表中是否有重复的元素。它使用了 set() 属性,该属性将会从列表中删除重复的元素。
  2.  
  3. def all_unique(lst):
  4. return len(lst) == len(set(lst))
  5.  
  6. x = [1,1,2,2,3,2,3,4,5,6]
  7. y = [1,2,3,4,5]
  8. all_unique(x) # False
  9. all_unique(y) # True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement