CodeNest

Lists and dictionaries

A list holds an ordered collection of values:

scores = [72, 95, 88]
scores.append(61)      # add to the end
print(len(scores))     # 4
print(scores[0])       # 72  (indexes start at 0)
print(sum(scores), max(scores), min(scores))

A dictionary maps keys to values:

ages = {"Ada": 36, "Linus": 28}
print(ages["Ada"])            # 36
for name, age in ages.items():
    print(name, age)

Try it

Print the total and highest score, then one line per person in the ages dictionary:

Total: 316
Highest: 95
Ada is 36
Linus is 28
Python in-browser · Python 3.13
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.