counting items

Michael Hartl mhartl at
Wed Jan 12 14:50:39 EST 2005

There's a great function called "walk" at that iterates over arbitrary
data (and is recursion-proof) at

It also supplies a recursion-proof way to flatten a list.  (Once you
can iterate over an arbitrary sequence, the flattened version is just
[element for element in walk(sequence)].)  I use both functions all the

Adding a flatten function (along with walk) to Python sounds like a
good idea to me.  Having used Mathematica for many years, which uses
Flatten[] all over the place, I was actually quite surprised to find
that Python didn't have it.


More information about the Python-list mailing list