Created
April 8, 2022 20:15
-
-
Save aaronshaver/12869752712d0cda29d6a5e318dc3392 to your computer and use it in GitHub Desktop.
Use a set (hashset) when possible
This file contains hidden or 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
# do: | |
vowels = set('aeiouAEIOU') | |
# rather than: | |
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] | |
# because searching for X in set is O(1) on average for hashset (O(n)) worst | |
# vs. O(n) on average for array, which is how Python list is implemented | |
# internally |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment