Sobes.tech
Junior — Middle

What data structures do you use in your projects?

sobes.tech AI

Answer from AI

In Python projects, I often use the following data structures:

  • Lists (list) — for ordered storage of elements with the ability to modify.
  • Tuples (tuple) — for immutable sequences.
  • Dictionaries (dict) — for storing key-value pairs, very convenient for quick access by key.
  • Sets (set) — for storing unique elements and set operations.

Example of using a dictionary to count the number of elements:

items = ['apple', 'banana', 'apple', 'orange']
count = {}
for item in items:
    count[item] = count.get(item, 0) + 1
print(count)  # {'apple': 2, 'banana': 1, 'orange': 1}