Check if all elements in a list are identical

前端 未结 22 2381
死守一世寂寞
死守一世寂寞 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 08:06

    I'd do:

    not any((x[i] != x[i+1] for i in range(0, len(x)-1)))
    

    as any stops searching the iterable as soon as it finds a True condition.

提交回复
热议问题