Sobes.tech
Junior — Middle

Can you explain what a data structure is and what it is used for?

sobes.tech AI

Answer from AI

Data structures are methods of organizing and storing data in memory or on disk that enable efficient operations on this data.

They are used for:

  • Fast data access
  • Efficient addition, removal, and search of elements
  • Memory usage optimization

Examples of data structures in Python:

  • Lists (list) — ordered mutable collections
  • Tuples (tuple) — ordered immutable collections
  • Dictionaries (dict) — key-value pair collections
  • Sets (set) — unordered unique elements

Example of using a list:

fruits = ['apple', 'banana', 'cherry']
fruits.append('orange')
print(fruits[0])  # outputs 'apple'