Skip to content

Instantly share code, notes, and snippets.

@pykong
Last active October 22, 2017 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pykong/58ef0a5a183c0db838095c0f7e3e9141 to your computer and use it in GitHub Desktop.
Save pykong/58ef0a5a183c0db838095c0f7e3e9141 to your computer and use it in GitHub Desktop.
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