itertools.flatten()? and copying generators/iterators.

Peter Otten __peter__ at web.de
Thu Oct 30 03:37:20 EST 2003


Francis Avila wrote:

>> for flatten_dict(). So you get some speed up at the cost of uglier though
>> still quite readable code and under the assumption that either all or no
>> instances of a class are iterable.
> 
> That's not always a good assumption to make, if we want to decide whether
> to iterate based upon some property of the object (which is actually how I
> originally discovered I needed a "flatten").
> 
> Perhaps we can combine both conditions and caching optimizations?

I didn't work this out, but I suppose the way to go is to allow three states
(ALWAYS, NEVER, NOCACHE) in the dictionary and only invoke itercond() on
cache misses and NOCACHE values.

Peter




More information about the Python-list mailing list