Last active
October 22, 2017 09:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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