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

Francis Avila francisgavila at yahoo.com
Wed Oct 29 21:41:38 EST 2003


"Francis Avila" <francisgavila at yahoo.com> wrote in message
news:vq0rg4l1uasj31 at 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





More information about the Python-list mailing list