Junior — Middle
Can you list the main data structures used in Python?
sobes.tech AI
Answer from AI
Main data structures in Python:
- Lists (list) — ordered mutable collections of elements.
- Tuples (tuple) — ordered immutable collections.
- Sets (set) — unordered collections of unique elements.
- Dictionaries (dict) — collections of key-value pairs.
Additionally, there are specialized structures from the collections module:
deque— a double-ended queue.defaultdict— a dictionary with default values.OrderedDict— a dictionary that preserves insertion order.
Example of using a list and a dictionary:
fruits = ['apple', 'banana', 'cherry']
prices = {'apple': 100, 'banana': 80, 'cherry': 120}