zip 2 sequences into 1

Tony Meyer t-meyer at ihug.co.nz
Thu Apr 22 00:10:32 EDT 2004


> How about
> 
>    itertools.chain(*zip(seq1, seq2, seq3, ...))

FWIW, this is faster (and nicer, IMO) than the suggestion I posted:

[using the 'flatten' function posted]
>>> flat.timeit()
8.434350455155613

[using my merge function]
>>> merg.timeit()
7.6710651772781162

[using itertools.chain]
>>> chai.timeit()
6.4707137359636491

=Tony Meyer





More information about the Python-list mailing list