List Flatten
bearophile
bearophileHUGS at lycos.com
Sun Oct 17 15:49:31 EDT 2004
Peter Otten:
>Have you considered generators?<
I haven't because I am still learning Python, and I still don't know
all the unusual features of it.
I'll try to improve, there are many things to learn.
>I have not timed it, I just prefer the generator for its clarity
(provided it is correct, I haven't tested it either).<
It seems correct, and the timings are a bit better than mine for some
cases (very nested lists) and a bit slowler for other cases (quite
flat lists). I think usual list are already quite flat (like 2D
arrays, etc).
>Generators may also save you a lot of memory for very large data
structures as you can iterate over a flat _view_ of your nested lists
without ever having to _create_ the large flat list.<
I understand; this is very interesting.
Jeffrey Froman's version is recursive, and I have refused such
versions because the stack is limited by default.
Thank you all for the comments and nice ideas,
a bear hug,
bearophile
More information about the Python-list
mailing list