Junior — Middle
Can you list the types of collection data structures you are familiar with?
sobes.tech AI
Answer from AI
In Python, there are several main types of collection data structures that are frequently used:
- list — an ordered, mutable list of elements, allowing duplicates.
- tuple — an ordered, immutable set of elements.
- set — an unordered collection of unique elements.
- frozenset — an immutable set.
- dict — a dictionary, mapping keys to values, with unique keys.
In addition to built-in types, there are collections from the collections module:
- deque — a double-ended queue with fast appends and pops from both ends.
- defaultdict — a dictionary with a default value for missing keys.
- OrderedDict — a dictionary that preserves the order of insertion (in newer Python versions, the built-in dict also preserves order).
- Counter — a dictionary subclass for counting hashable objects.
Each structure is suitable for different tasks, for example, list is convenient for sequences with indexing, set for unique elements and quick membership tests, dict for associative data.