A Faster Way...

Klaus Alexander Seistrup dh47302 at yahoo.com
Tue May 10 18:17:00 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, .....

If the order is unimportant you could use:

#v+

>>> tuple(set(range(10)) | set(range(20,30)))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29)
>>> 

#v-

Cheers,

-- 
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/



More information about the Python-list mailing list