A query about list

Dave Benjamin ramen at lackingtalent.com
Fri Oct 10 05:25:31 EDT 2003


Hi, Peter!

In article <bm5qsj$1ii$02$1 at news.t-online.com>, Peter Otten wrote:
> Here's a variant that might interest you. It entirely omits indices and
> slices and can deal with recursively nested sequences.
> You need not create a list at all, if you want to iterate over the elements
> one at a time.
> 
> def flatten(seq):
>     """ Flatten a sequence of sequences of sequences...
>     """
> ...

Nice work! I've occasionally used a flatten after a bunch of list processing
because it made a sequence of not-quite-parallel operations seem more
parallel. I saw it as unfortunate that I was creating all of these extra
lists, but it seemed a fair tradeoff between clarity and efficiency. I think
your example shows that if I had only understood laziness better (hehe) I
might not have had to make a tradeoff at all.

Thanks,
Dave

-- 
.:[ dave benjamin (ramenboy) -:- www.ramenfest.com -:- www.3dex.com ]:.
: d r i n k i n g   l i f e   o u t   o f   t h e   c o n t a i n e r :




More information about the Python-list mailing list