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
- Weeknotes: asynchronous LLMs, synchronous embeddings, and I kind of started a podcast - 22nd November 2024
- Notes from Bing Chat—Our First Encounter With Manipulative AI - 19th November 2024
- Project: Civic Band - scraping and searching PDF meeting minutes from hundreds of municipalities - 16th November 2024