A Faster Way...
Fredrik Lundh
fredrik at pythonware.com
Tue May 10 13:14:37 EDT 2005
andrea.gavana at agip.it wrote:
> If I simplify the problem, suppose I have 2 lists like:
>
> a = range(10)
> b = range(20,30)
>
> What I would like to have, is a "union" of the 2 list in a single tuple. In
> other words (Python words...):
>
> c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, .....
>
> and so on.
here are some alternatives:
c = sum(zip(range(10), range(20, 30)), ())
or
c = []
[c.extend(x) for x in zip(range(10), range(20, 30))]
c = tuple(c)
or
from _tkinter import _flatten
c = _flatten(zip(range(10), range(20, 30)))
(timeit is your friend)
</F>
More information about the Python-list
mailing list