Pcornel
Networking · Automation and Artificial Intelligence

Python Data Structures

Cheat sheet · https://pcornel.dk/topic.php?topic=91

Back to the Topic

Answer

Python data structures hold structured network data: lists (ordered items), dictionaries (key/value), nested combinations of both as returned by APIs, plus tuples and sets.

Remember

data['key'] raises KeyError if missing — use data.get('key'). API responses are usually a dict containing a list of dicts: loop with for item in data['items']:. Copy before modifying a list you are looping over. json.loads() turns JSON text into these structures.

First checks

  • python3 --version and which python3 — interpreter in use.
  • python3 -m venv .venv && . .venv/bin/activate — isolated environment.
  • pip list — installed libraries (requests, netmiko, ncclient, pyyaml).
  • python3 -m py_compile script.py — syntax check.
  • python3 -i script.py / print(type(x), x) — inspect values while debugging.

Verify in this order

correct interpreter and libraries → script parses → inputs read and validated → logic runs → output or change verified

Where it usually breaks

physical/link dependency → local object state → peer/control state → policy → forwarding/adjacency → end-to-end result

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=91

Confirmation

Confirm action

Continue?