Wednesday, 9/30
Choosing a data structure
Checkpoint 2 Due Sunday, 10/04
Open in a new tab
· press f for fullscreen, o for an overview
Lists and records
Open the notebook first load takes about 25 secondsThe notebook is loading. The first load takes about 25 seconds.
Or run it on your own machine, which is how this course works from the second session on.
- Download
02-lists-and-records.pyinto your project'snotebooks/folder. -
Run
uv run marimo editfrom the project, with no file name. You get a page listing every notebook in it.
uv run 02-lists-and-records.py runs the cells and exits without showing you
anything, which looks like nothing happened. No project yet?
uvx marimo edit opens whichever folder you are in.
·
Jupyter version, which
reads without being run but has no working controls.
Collections and APIs
Open the notebook first load takes about 25 secondsThe notebook is loading. The first load takes about 25 seconds.
Or run it on your own machine, which is how this course works from the second session on.
- Download
03-collections-and-apis.pyinto your project'snotebooks/folder. -
Run
uv run marimo editfrom the project, with no file name. You get a page listing every notebook in it.
uv run 03-collections-and-apis.py runs the cells and exits without showing you
anything, which looks like nothing happened. No project yet?
uvx marimo edit opens whichever folder you are in.
·
Jupyter version, which
reads without being run but has no working controls.
TL;DR#
Today the agent in VS Code got its rules from AGENTS.md, and we watched it install a package with uv, commit and push. Then the review polls, a review of types, and first looks at records, tuples and sets. Choosing a data structure and a first request to an API will come next Wednesday. The habit worth keeping: when something breaks, ask the agent in VS Code first. It can read your terminal and your files, which a chat window in the browser cannot.
What we covered#
AGENTS.md holds your project's rules for the agent. It goes in the root folder of your repository, the same folder as README.md, and the name is spelled exactly AGENTS.md. The agent in VS Code reads it with every request. When asked to install requests, it ran uv add requests and left pip alone, because the file says so. A chatbot in the browser, asked the same question, answered with pip install. To confirm the file was read, expand References under the agent's answer and find AGENTS.md in the list. marimo's panel does not read the file; the Custom Rules you pasted into marimo do the same job there.
An agent can act on your whole project. It can run commands in the terminal, edit files, commit and push. While you are learning, keep the default permissions and read each command before you allow it.
A short message costs tens of thousands of tokens. The agent sends its own instructions, the definitions of every tool it is allowed to use, and your AGENTS.md along with every message, so even "hi" is large. Developer: Show Chat Debug View in the Command Palette shows what went out.
An if/elif chain stops at the first true branch. With total = 250, if total >= 100 is true, so the elif total >= 200 branch never runs. Put the larger threshold first. If no branch is true, a variable that only the branches set never exists, and the next line that uses it stops with NameError. Add a final else, or give the variable a starting value before the if.
Every value has a type. type() tells you which:
10 / 2is5.0, afloat, and10 // 2is5, anint."hi"is astr, andlen("hi")is 2 because it counts characters.- A comparison has a value too:
90 < 100isTrue, of typebool. Aboolis eitherTrueorFalse, and what followsiforelifis one. andis true only when both sides are true;oris true when either side is;notflips abool.
Some characters do not show when printed. "\n" is a line break and counts as one character, so len("hi\n") is 3. Text read from a file or a spreadsheet cell often carries a line break or spaces at either end, and so does a key copied from an email. .strip() removes spaces, tabs and line breaks from both ends.
Indentation decides what belongs to a loop. total = 0 inside the loop runs on every pass, so the total starts over each time and only the last charge survives. Put it above the loop to keep a running total.
Text compares character by character. max(["9.50", "16.75", "22.25"]) returns "9.50", because "9" comes after "1" and "2". Every character has a number, its Unicode code point, and text is compared by those numbers: ord("9") is 57 and ord("d") is 100. That is also why "9.50" can be compared with "Dave": both are text. A number and text cannot be compared at all, so "Dave" < 9.5 stops with TypeError. Convert with float() before you compare values that should be numbers.
append adds one item; extend adds each item. order_lines.append(["stapler", "tape"]) adds a single item, which is itself a list, so the order has three lines. order_lines.extend(["stapler", "tape"]) adds two, for four.
A record is read by name. A record is a dictionary: each key is a field name, and each value is that field's value, the way a column name labels a cell in one row of a table. A record has no positions, so first_order[0] stops with KeyError: 0, and keys are case sensitive, so first_order["freight"] stops too. len(first_order) is 7, one for each key and value pair. JSON, the format most APIs send, has the same shape, which is why an API's reply becomes a dictionary in Python.
The outermost bracket tells you what you have. orders starts with [, so it is a list; each item starts with {, so each is a record. A list of records is a table. type(orders) and type(orders[0]) confirm it.
A tuple cannot change after it is made. It reads by position like a list, and assigning to a position stops with TypeError: 'tuple' object does not support item assignment. Use one for a value whose parts are fixed, such as a holding's ticker, shares and price. Because it cannot change, a tuple can be a dictionary key and a list cannot: {(12, 25): "Christmas"} works. Notebook 3, section 2, has the rest.
A set holds each value once. set(traded_tickers) turns a list of trades into the distinct tickers. For two portfolios, a & b is what is in both, a - b is what is in a and not in b, and a | b is everything in either.
A tool worth bookmarking#
Python Tutor runs a few lines of Python one step at a time and draws each variable as it changes. We used it for the running total that kept starting over. Paste the code, click Visualize Execution, and step through it.
Setting up the agent#
The Babson model in VS Code is set up in Your AI Tools and Babson Key, section Add the Babson model. When Manage Language Models does not appear in the Command Palette, open the Chat view and sign in with GitHub first. After you paste the model's settings, press Shift+Alt+F (Windows) or Shift+Option+F (macOS) to format the file: if it will not format, a bracket, quotation mark or comma is missing. When it still does not answer, email me the exact error message.
From the lightning talks#
No-code tools have code underneath. A drag-and-drop tool such as Alteryx still stores each workflow as text, and its menus name the same operations this course teaches:
- Join combines two tables on a shared column. An inner join keeps only the rows that match in both. We will write joins in SQL.
- Parsing pulls a value in a known format out of messy text, such as a date typed several different ways.
- Regular expressions describe a pattern in text, such as every way a user might type a phone number, so that all of them can be rewritten in one standard form.
What the data says about data centers, following the talk on 9/23:
- A pool in Exmouth, UK, heated by 28 kW of servers was predicted to cut its gas use by 62% (Data Centre Review, 2023)
- Utah's largest proposed campus would use at most about 1.4% of the state's municipal water (Grist, 2026; Utah Foundation, 2023)
- Data-center load drove 40% of PJM's 2027/28 capacity cost, $6.5B of $16.4B (Utility Dive, 2026)
- IDC expects PC prices to rise 17% in 2026 as memory goes to AI servers (IDC, 2026; TrendForce, 2026)
- US data centers used 4.7% of US electricity in 2024, projected at 11.8% by 2030 in a range of 9.5% to 15.3% (LBNL, 2026)
Where counties are pausing new data centers: dc.zhili.dev. Further reading: Water, Noise, Power: The Real Costs of Data Centers (Gradient Flow, 2026).
Going further#
Going further in a notebook is optional. Skip it and you lose nothing. In Mini Project 1 it is required, in any direction you choose, and it does not have to work.
Public links#
- Session page, where
03-collections-and-apis.pyis, under the 03 · Collections and APIs tab. The Downloads page does not have it - Mini Project 1, the full instructions and the starter notebook
- Your AI Tools and Babson Key, including
AGENTS.md - Your agent's rules, the text for
AGENTS.md - Python handbook, Collections, for lists, dictionaries, tuples and sets
Before next session#
Checkpoint 2 closes Sunday 10/04, and it now includes today's work:
- Finish notebook 2,
02-lists-and-records.py, including sections 4 to 6: the Orders table, your One row is... sentence in section 5, and The Portfolio in section 6. - Work through sections 1 to 3 of notebook 3,
03-collections-and-apis.py: more on dictionaries, tuples and sets. Download it from the session page, under the 03 · Collections and APIs tab. Section 4 onward is next week's. - Commit
AGENTS.mdin the root folder of your repository, the same folder asREADME.md. Copy the text from Your agent's rules, then ask the agent in VS Code to install therequestspackage, so that it appears in yourpyproject.toml. - Commit and push as you go. Nothing counts until it is on github.com. Write each commit message yourself; the agent may improve the wording.
Mini Project 1 is due Sunday 10/11. Choose a project and write your plan in words before you ask your agent anything. The instructions and the starter notebook are on the Mini Project 1 page.
In the handbook
Reference for this session. None of it is assigned.