counting items

Leif K-Brooks eurleif at ecritters.biz
Wed Jan 12 14:52:50 EST 2005


Paul McGuire wrote:
> Considering how often this comes up, might there be a place for some sort of
> flatten() routine in the std dist, perhaps itertools?

A problem I see is that itertools tries to work across all iterable 
types, but flattening can't always be a generalized operation. For 
instance, a naive flattening function might turn the list ['foo', 'bar'] 
into ['f', 'o', 'o', 'b', 'a', 'r'] -- or worse, fall into infinite 
recursion -- when the intended result would be to leave the list 
unchanged. Of course, a generalized flattening function could take an 
argument listing types to ignore, but that can get very complicated very 
fast.



More information about the Python-list mailing list