Sobes.tech
Junior — Middle

Can you list the main types of collections used in Python?

sobes.tech AI

Answer from AI

In Python, the main collection types include:

  • list — an ordered, mutable list of elements.
  • tuple — an ordered, immutable set of elements.
  • set — an unordered collection of unique elements.
  • dict — a dictionary mapping keys to values.

Additionally, the standard library includes specialized collections, such as:

  • collections.deque — a double-ended queue.
  • collections.Counter — a counter for hashable objects.
  • collections.OrderedDict — a dictionary that preserves insertion order (before Python 3.7, after which the built-in dict also preserves order).

Example of using list and dict:

fruits = ['apple', 'banana', 'cherry']
prices = {'apple': 100, 'banana': 80, 'cherry': 120}
Can you list the main types of collections used in… - sobes.tech