Skip to content

Instantly share code, notes, and snippets.

@pykong pykong/all_equal.py
Last active Oct 22, 2017

Embed
What would you like to do?
Ordered those from "most Pythonic" to "least Pythonic" and "least efficient" to "most efficient". - the len(set()) solution is idiomatic, - but constructing a set is less efficient memory and speed-wise.
>>> lst = ['a', 'a', 'a']
>>> len(set(lst)) == 1
True
>>> all(x == lst[0] for x in lst)
True
>>> lst.count(lst[0]) == len(lst)
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.