Fork me on GitHub

Sunday, October 25, 2009

Infinite lists in python

My first post from Uganda :)

As I am working in Django now I think I will post more on python. I had worked on python before but that was long time back and mostly on system admin stuff. So working on python now for developing web based applications and getting to understand things like object orientation, functional programming, TDD, Ruby and more I think it has changed my way of working with python a lot.

This post is mostly about creating infinite lists in python. Infinite lists are an example of lazy evaluation mostly rooted in functional programming. The idea is we don't construct elements of list but what we do is give a way to construct the next element of the list and let it construct the list when we need (we still need to stop construction of elements depending on some condition). Infinite lists are also rightly called streams. In python, it is easy to use develop infinite lists using generator as shown in the examples below.

Examples of infinite list in python

Increment Example -

Fibonacci Example -

Thursday, October 8, 2009

A simple PingPong example based on Erlang

This is a test for Github's gist script embed in my blog :).