← Lessons/Lists, Dicts & Comprehensions
← Lists, Dicts & Comprehensions

A list and a loop

Learn

A list: an ordered row of lockers

A list is an ordered sequence of values, like a numbered row of lockers. Order is preserved, items can repeat, and you reach any item by its position, starting at 0:

regions = ["eu-west-1", "us-east-1"]
print(regions[0])     # "eu-west-1" — the first locker
print(len(regions))   # 2           — how many are filled

You rarely index by hand, though: you loop over the whole list with for, which hands you one item at a time.

for r in regions:
    print(f"deploying to {r}")

Make a list servers of "web", "api", "db". Loop over it printing server: <name> for each, then print count: 3 using len().

$ python3 main.py
Loading...

Output

Run your solution to see its output here.