Check if all elements in a list are identical

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

    def allTheSame(i):
        j = itertools.groupby(i)
        for k in j: break
        for k in j: return False
        return True
    

    Works in Python 2.4, which doesn't have "all".

提交回复
热议问题