Sobes.tech
Junior — Middle

Kas saaksid loetleda Pythonis kasutatavaid peamisi kogumite tüüpe?

sobes.tech AI

Vastus AI-lt

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 (up to Python 3.7, after which order is preserved in a regular dict).

Example of using list and dict:

fruits = ['apple', 'banana', 'cherry']
prices = {'apple': 100, 'banana': 80, 'cherry': 120}