[Python-Dev] Suggestion for a new built-in - flatten

Raymond Hettinger rhettinger at ewtllc.com
Fri Sep 22 22:14:58 CEST 2006

[Michael Foord]
>I have a suggestion for a new Python built in function: 'flatten'.
> ...
> There are several different possible approaches in pure Python, 
> but is this an idea that has legs ?

No legs.

It has been discussed ad naseum on comp.lang.python.  People seem to
enjoy writing their own versions of flatten more than finding legitimate
use cases that don't already have trivial solutions.

A general purpose flattener needs some way to be told was is atomic and
what can be further subdivided.  Also, it not obvious how the algorithm
should be extended to cover inputs with tree-like data structures with
data at nodes as well as the leaves (preorder, postorder, inorder
traversal, etc.)

I say use your favorite cookbook approach and leave it out of the


More information about the Python-Dev mailing list