Small games and the code behind them. Short coding lessons with real code and real output.

New Delhi
Full video, Packaging with uv: piped.video/iwxg14e4ro4
A Python script can list its own dependencies in a comment. 🐍 # /// script # dependencies = ["requests"] # /// -> uv run installs it #Python #Coding
1
1
4
How to package Python code with uv, in 4 images. 🐍 Name a command, run uv build, share the wheel. #Python #Coding
1
1
41
A pytest test is just an assert, in 4 images. 🐍 #Python #Coding
1
1
19
A pytest test is just an assert. 🐍 def test_add(): assert add(2, 3) == 6 -> assert 5 == 6 #Python #Coding
1
1
19
Full video, HTTP and JSON APIs: piped.video/etiI3qWhWi0
1
Fetch JSON from the web with urlopen and json.load, in 4 images. 🐍 #Python #Coding
1
1
13
How to call a web API in Python, in 4 images. 🐍 urlopen the URL, json.load the response: you get a dictionary. #Python #Coding
1
1
5
Full video, HTTP and JSON APIs: piped.video/etiI3qWhWi0
1
Fetch JSON from the web with only the standard library. 🐍 urlopen(url, timeout=10) json.load(r)["title"] -> delectus aut autem #Python #Coding
1
1
45
Full video, Trees and traversal: piped.video/ZYZUSZJeNa4
1
Walk a tree left, node, right and get sorted values, in 4 images. 🐍 #Python #Coding
1
1
10
Full video, Trees and traversal: piped.video/ZYZUSZJeNa4
1
Walk a binary search tree left, node, right and the values come out sorted. 🐍 inorder(tree) -> [1, 2, 3] #Python #Coding
1
1
8
How an in-order walk visits a binary tree, in 4 images. 🐍 Walk left, print the node, walk right: the values come out sorted. #Python #Coding
1
2
32
Top 3 numbers without sorting the whole list, in 4 images. 🐍 heapq.nlargest keeps a small heap of the best few. #Python #Coding
1
1
11
Need the top 3 numbers? Don't sort the whole list. 🐍 heapq.nlargest(3, nums) -> [9, 7, 4] #Python #Coding
1
1
10
Python 3.15 frozendict, in 4 images. 🐍 A built-in dict that can't change, so it can be a dict key. #Python #Coding
1
1
17
Python 3.15 finally has an immutable dict. 🐍 frozendict is built in, and unlike a dict it can be a key: shops = {menu: "today"} #Python #Coding
1
2
91
How a Python dict finds a key, in 4 images. 🐍 Hash the key, jump to the slot: lookup is O(1). Two keys in one slot is a collision. #Python #Coding
1
1
16
Sorting by length in Python, in 4 images. 🐍 sorted(words, key=len) sorts by any rule you give it, and ties keep their order. #Python #Coding
1
2
80
Sort words by length in Python. 🐍 sorted(["pear", "fig", "kiwi", "apple"], key=len) → ["fig", "pear", "kiwi", "apple"] Ties keep their order. #Python #Coding
1
2
48
Python bisect, in 4 images. 🐍 Find where a value belongs in a sorted list, and keep it sorted with insort. #Python #Coding
1
1
51
Python has binary search built in. 🐍 bisect.insort(nums, 6) keeps a sorted list sorted. bisect.bisect_left(nums, 8) gives 3: the position where 8 belongs. #Python #Coding
2
2
23
Python binary search, in 4 images. 🐍 Check the middle of a sorted list and drop half. A million items take about 20 steps. #Python #Coding
1
1
49
A function with no base case, in 4 images. 🐍 Python stops it at about 1000 calls with a RecursionError. #Python #Coding
1
2
18
A function that calls itself forever? def dive(n): return dive(n + 1) Python stops it at about 1000 calls: RecursionError: maximum recursion depth exceeded The fix: a base case. 🐍 #Python #Coding
1
2
17
Python recursion, in 4 images. 🐍 A function calls itself on a smaller problem. The base case stops it. #Python #Coding
2
2
22
List to text, then back: text = json.dumps(todos) json.loads(text) == todos # True Note that False becomes false in the text. And a tuple comes back as a list. 🐍 #Python #Coding
1
2
18
Full video, Linked Lists: piped.video/LV1J7lLj6zY
1
1
Getting the third item of a linked list, in 4 images. 🐍 No index: follow the links, one hop at a time. #Python #Coding
2
2
11
A Python list to text and back, in 4 images. 🐍 json.dumps makes the text, json.loads gives the same list back. #Python #Coding
2
1
14
A linked list has no index. The third item is two hops: head = Node("a", Node("b", Node("c"))) print(head.next.next.value) # c The hundredth is 99 hops. O(n). 🐍 #Python #Coding
1
2
22