Python Lists, Dictionaries and Loops for Excel Users

Python Lists, Dictionaries and Loops for Excel Users

📎 This article includes 2 downloadable practice files ↓

⏱ 2 min readUpdated 28 September 2026

Before pandas, it helps to understand plain Python’s core tools. Almost every automation script is built from lists, dictionaries and loops.

In this article
  1. Lists: an ordered column
  2. Dictionaries: a lookup table
  3. Loops: do something for every item
  4. Putting them together: totals by region
  5. Continue learning

Lists: an ordered column

regions = ["North", "South", "East", "West"]
print(regions[0])        # North  (counting starts at 0)
print(len(regions))      # 4
regions.append("Central")
print(regions[-1])       # Central (last item)

A list is like one Excel column: ordered, and you can add, remove and sort items.

Advertisement

Dictionaries: a lookup table

managers = {"North": "Vikram", "South": "Lakshmi", "East": "Priya"}
print(managers["North"])             # Vikram  — like VLOOKUP
print(managers.get("West", "None"))  # None    — IFERROR built in
managers["West"] = "Farhan"          # add or update

Loops: do something for every item

sales = [12500, 8400, 15200, 6100]
total = 0
for amount in sales:
    total += amount
print(total)          # 42200  — like SUM

big = [s for s in sales if s > 10000]   # like FILTER
print(big)            # [12500, 15200]

Putting them together: totals by region

rows = [("North", 12500), ("South", 8400), ("North", 15200), ("East", 6100)]
totals = {}
for region, amount in rows:
    totals[region] = totals.get(region, 0) + amount
print(totals)   # {"North": 27700, "South": 8400, "East": 6100}  — a pivot table
💡 Python cares about indentation: the lines inside a loop must be indented the same amount (4 spaces is standard).

Next step: pandas for Excel users, which does all of this on whole tables.

📎 Practice files for this article

⬇ Download all 2 files (ZIP · 2 KB)

  • 🧾
    orders.csv (60 sample orders)Plain CSV used by the exercises — open it in Excel first to see what you are working with.
    ⬇ CSV · 2 KB
  • 🐍
    exercises.py — 8 exercises with answersEach exercise is the Python version of an Excel habit: COUNTA, SUMIF, pivot, FILTER, SORT(UNIQUE()).
    ⬇ PY · 2 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong