Splice two lists

Alex Martelli aleaxit at yahoo.com
Sat May 6 20:53:40 EDT 2006


danmcleran at yahoo.com <danmcleran at yahoo.com> wrote:

> Is there a good way to splice two lists together without resorting to a
> manual loop? Say I had 2 lists:
> 
> l1 = [a,b,c]
> l2 = [1,2,3]
> 
> And I want a list:
> 
> [a,1,b,2,c,3] as the result.
> 
> I've been searching around but I can't seem to find a good example.

One way:

result = 6*[None]
result[0::2] = l1
result[1::2] = l2


Alex



More information about the Python-list mailing list