Infinite Python Data Structures
6th October 2003
Hans Nowak has been churning out some really interesting Python stuff recently. He’s been experimenting with Self style objects in Python (similar in many respects to objects in Javascript), developing Wax, a coder friendly wrapper around wxPython, working on a Python framework for writing text adventure games and most recently experimenting with streams in Python using generators.
Streams are a fascinating concept: they provide a way of defining infinite sized data structures, such as an array of all numbers that are multiples of 7. By only calculuating items when they are requested these seemingly impossible data structures can exist and be processed in a similar way to normal arrays. As Hans points out, Python generators aren’t quite as elegant for this purpose as Scheme’s stream implementation or Haskell’s recurive list declarations but this use for them does help show why generators are such a powerful tool.
More recent articles
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024