Junior — Middle
Can you list the main data structures and briefly describe their use?
sobes.tech AI
Answer from AI
Main data structures in Python and their applications:
-
List (
list) — an ordered mutable collection of elements. Used for storing sequences that require quick access by index and the ability to modify. -
Tuple (
tuple) — an ordered immutable collection. Suitable for storing fixed sets of data. -
Set (
set) — an unordered collection of unique elements. Used for operations involving uniqueness, union, intersection. -
Dictionary (
dict) — an unordered collection of key-value pairs. Allows quick search, addition, and removal of elements by key.
Example of using a list and a dictionary:
fruits = ["apple", "banana", "cherry"] # list
prices = {"apple": 100, "banana": 80} # dictionary
print(fruits[1]) # banana
print(prices["apple"]) # 100