Python: determining whether any item in sequence is equal to any other

前端 未结 5 1107
失恋的感觉
失恋的感觉 2021-01-04 19:40

I\'d like to compare multiple objects and return True only if all objects are not equal among themselves. I tried using the code below, but it doesn\'t work. If

5条回答
  •  长情又很酷
    2021-01-04 20:23

    You can check that all of the items in a list are unique by converting it to a set.

    my_obs = [obj1, obj2, obj3]
    all_not_equal = len(set(my_obs)) == len(my_obs)
    

提交回复
热议问题