Skip to content

Python Essentials for ML

Lists, Dicts & Comprehensions

8 min+65 XPStep 1/10

Lists are ordered columns; dicts are labeled rows

A list is an ordered sequence — think of it as one column of a dataset:

  • losses = [0.9, 0.5, 0.3]
  • losses[0] → 0.9 — indexing starts at zero
  • losses[-1] → 0.3 — negative index counts from the end
  • losses[:2] → [0.9, 0.5] — slicing takes a range

A dict maps names to values — one row of a dataset: {'epoch': 3, 'loss': 0.5}. Pull values back out by name: run['loss'] → 0.5.

A list of dicts — [{'loss': 0.9}, {'loss': 0.5}] — is already a tiny table. Which is convenient, because that's exactly what pd.DataFrame() accepts.

insight

Learn to see `list` = column, `dict` = row, `list of dicts` = table. pandas is just that mental model with superpowers.