Check if all elements in a list are identical

前端 未结 22 1967
死守一世寂寞
死守一世寂寞 2020-11-22 07:45

I need a function which takes in a list and outputs True if all elements in the input list evaluate as equal to each other using the standard equal

22条回答
  •  长发绾君心
    2020-11-22 07:51

    You can convert the list to a set. A set cannot have duplicates. So if all the elements in the original list are identical, the set will have just one element.

    if len(set(input_list)) == 1:
        # input_list has all identical elements.
    

提交回复
热议问题