counting items
Michael Hartl
mhartl at post.harvard.edu
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
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/118845
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
time.
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.
Michael
More information about the Python-list
mailing list