Lists and dictionaries

Choose a collection that fits the information your program needs to store.

A list stores an ordered sequence of values and uses numeric indexes starting at zero. A dictionary stores key-value pairs, which can describe one structured record.

Store society information

python · static example

societies = ["Robotics", "Coding", "Design"]
student = {"name": "Asha", "semester": 3}

print(societies[0])
print(student["name"])

Use square brackets with an index for a list and a key for a dictionary.

Sample output
Robotics
Asha

Labeled sample only — nothing was run on this page.

Case study

Scenario

You need to store several society names and the details for one student, including name and semester.

Task

Which structure would you use for each, and why?

Explanation / example

Use a list for the ordered set of society names and a dictionary for the student's named fields.

Knowledge check

How do you access the first item in `items = ["a", "b"]`?

Pick an answer to check.

    Lists and dictionaries · Python for Beginners | Nestify Campus