Maurice Agireh
last year
Mauricecountry asked

What are lists and dictionaries?

Kelish Rai
Expert
last year
Kelish Rai answered

In Python, lists and dictionaries are two important data types that allow you to store and organize data in different ways.

A list is an ordered collection of items where each item is identified by an index (starting from 0). Lists are created using square brackets []. For example,

fruits = ["apple", "banana", "cherry"]
print(fruits[0])  # Output: apple

A dictionary is a collection of key-value pairs where each value is accessed by its unique key, not by index. Dictionaries are created using curly braces {}. For example,

person = {"name": "Alice", "age": 25}
print(person["name"])  # Output: Alice

Both are very flexible and widely used for different purposes in Python programming.

Python
This question was asked as part of the DSA with Python course.