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

From: Francis Avila (francisgavila_at_yahoo.com)
Date: 10/30/03


Date: Wed, 29 Oct 2003 21:41:38 -0500


"Francis Avila" <francisgavila@yahoo.com> wrote in message
news:vq0rg4l1uasj31@corp.supernews.com...
> As expected, given the same test tree (which doesn't exercise itercond),
the
> speed is about the same.

*Ahem*:

> def flatten_fastcond(s, isScalar, itercond=lambda o: None):
...
> for subelem in flatten_dict(elem, isScalar):
> yield subelem

I thought it was a little strange that it was *exactly* the same, given the
function call...

Corrected (still not much difference, though):

...>python timeit.py -c -s"import flatten" "flatten.pro_dict()"
100 loops, best of 3: 7.22e+003 usec per loop

...>python timeit.py -c -s"import flatten" "flatten.pro_fastcond()"
100 loops, best of 3: 7.33e+003 usec per loop

> I'll make up some fancy tree later to test out itercond.

Well, should have made it sooner. I would have noticed an empty list...

--
Francis Avila


Relevant Pages