About Algorithm Performance

Average case time complexity of membership tests in sets are O(1) vs O(n) for lists.

Michael Galarnyk

In other words,

  • if you want to find if a value exists in a list, each value of a list will be checked, and
  • if you want to find a value in a set, a single hashed value will be checked.

Tips and Tricks Programming Wisdom Architecture Python 3 JavaScript