The Data Structures workbench

Pyodide, print, files, Run, Reset, and privacy.

The Data Structures app is a Python editor that runs in WebAssembly (Pyodide). When the status line says Python is ready, you have the standard library, including heapq and collections.

Goal

Know how Run, print, files, and Reset work before you count operations.

Run code

Paste into the editor and press Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS). The console is stdout. Use print.

from collections import deque

print(deque(["Nairobi", "Nakuru"]))

Print the cost

xs = ["Nairobi", "Mombasa", "Kisumu"]
steps = 0
for i, city in enumerate(xs):
    steps += 1
    if city == "Kisumu":
        print("index", i, "steps", steps)
        break

A silent loop teaches nothing about analysis.

Files live in /uploads

Click Add files and choose edges.csv. After that:

from pathlib import Path

print(Path("edges.csv").read_text(encoding="utf-8").splitlines()[:3])

Privacy

Python runs in this tab. Uploads live in IndexedDB on this device.

Pitfall

list.sort and dict are O-fast in C. When a chapter asks you to count, write the loop. Production code should use the built-in.