Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
Created April 8, 2022 20:15
Show Gist options
  • Save aaronshaver/12869752712d0cda29d6a5e318dc3392 to your computer and use it in GitHub Desktop.
Save aaronshaver/12869752712d0cda29d6a5e318dc3392 to your computer and use it in GitHub Desktop.
Use a set (hashset) when possible
# 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