Process and Manipulate Data with Python Structures

By the end of this lesson, you'll be able to

  • Store, index, and modify data using Python's core structures — lists, tuples, dicts, and sets — and know which one fits a given situation
  • Read and write the key-value and membership patterns (.get() with defaults, the tally pattern, set intersection) that show up constantly in agent state and API payloads
  • Use comprehensions to build lists, dicts, and sets in a single expression instead of a manual loop-and-append

Why it matters

Agent state, tool call arguments, and API responses are almost entirely built from these four structures nested inside each other — a list of dicts, a dict of tuples, tags stored as a set. Knowing exactly which structure fits which situation, and being fluent in comprehensions rather than always reaching for a manual loop, is what makes reading and writing agent code fast instead of laborious.