定义一个列表
lst = ['a', 'a', 'a']方法一
len(set(lst)) == 1len(set())解决方案是惯用的,但是构造一组内存效率较低,速度较慢。
方法二
all(x == lst[0] for x in lst)方法三
lst.count(lst[0]) == len(lst)
lst = ['a', 'a', 'a']len(set(lst)) == 1len(set())解决方案是惯用的,但是构造一组内存效率较低,速度较慢。
all(x == lst[0] for x in lst)lst.count(lst[0]) == len(lst)
评论区