What is the time complexity of common list, dict and set operations?

Python lists, dictionaries and sets · Freshers and experienced

Model answer

List: index and append are O(1) on average, searching with in is O(n), insert at the front is O(n). Dict and set: lookup, insert and delete are O(1) on average. Choose a set or dict when you test membership often.

Learn this topic

Dictionaries, Tuples and Sets in Python in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions