Functional Python - Itertools Exploration
Well, time passes, and my 30days challenges are continuing. January: no Twitter, February: no beer, and the month just passed, March: Meditation. I didn’t do too well on the meditation front, but that hasn’t put me off. I’ll reflect on that perhaps another time.
Now it’s a new month, and a new challenge. Although I don’t see it so much of a challenge, but something I want to use the challenge mechanism to complete. In my activities with CodeClub and the MadLab U-18 CoderDojo activities I’ve a refreshed interest in coding at the core, and have been looking at and using Scratch and Python in earnest. And in wondering and discussing how to present approaches to coding, and in particular some Python idioms (for example, see this question on ‘pedestrian’ vs ‘functional’ approaches), I’m developing a keen interest in the functional programming features in Python. I was particularly taken by this video: http://www.youtube.com/watch?v=EnSu9hHGq5o and did some more research, combining what I was learning with the functions map, filter and reduce, also of course available in many other languages.
All roads seemed to lead to itertools, a Python library that “implements a number of iterator building blocks inspired by constructs from APL, Haskell and SML”. So this month I’d like to investigate the functions in this library, one at a time. I’m not sure what that investigation will look like, but I know I’d like to have a look at each one in turn, find examples of how they might be used, and write a little bit about them. The writing part is interesting; I felt that this WordPress-based blog was slightly too formal (and cumbersome?) for what I wanted, and hankered after a Wiki-based environment, with minimal edit friction and the ability to build document and page structure relationships dynamically. I’d had one on this host a (very) long time ago, called “space”*, and it was a MoinMoin powered one. That’s Python-based, and it served me well, so I’ve just installed a new instance. I’ll use that to help me on my itertools voyage of discovery. Wish me bon voyage!
* Gosh, there are a few references to “space” still around in code, such as here!