Check if all elements in a list are identical

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

    Can use map and lambda

    lst = [1,1,1,1,1,1,1,1,1]
    
    print all(map(lambda x: x == lst[0], lst[1:]))
    

提交回复
热议问题