Python - alternating lists
Question: I have two lists in python:

    
    
    l = [1,1,1,1,1,1]
    b = ['-', 2, 2, 2, '-', 2]
    

In the end, I'd like to have a list like this:

result = [1, 1, 2, 1, 2, 1, 2, 1, 1, 2]

Algorithm: If there is a '-' in b, do nothing, else append element from b
after element in l at same index (Second 2 from b should go after second 1 in
l). How can I do this?

    
    
        for idx, i2 in enumerate(b):
        if i2 != '-' and count == 1:
            l.insert(prev+2,i2)
            prev = prev+2
            print "in if1"
            print l
            print prev
        elif i2 != '-' and count == 0:
            l.insert(idx+1,i2)
            prev = idx+2
            count = 1
            print "in if2"
            print l
            print prev
    


Answer: 
    l, b = [1,1,1,1,1,1], ['-', 2, 2, 2, '-', 2]
    print [item for items in zip(l, b) for item in items if item != '-']
    

**Output**

    
    
    [1, 1, 2, 1, 2, 1, 2, 1, 1, 2]
    

If the number of elements in either of the lists is not going to be equal to
the other, you can use
[`itertools.izip_longest`](http://docs.python.org/2/library/itertools.html#itertools.izip_longest)
like this

    
    
    l, b = [1,1,1,1,1,1], ['-', 2, 2, 2, '-', 2, 2, 2]
    from itertools import izip_longest
    print [e for items in izip_longest(l,b) for e in items if e != None and e != '-']
    

**Output**

    
    
    [1, 1, 2, 1, 2, 1, 2, 1, 1, 2, 2, 2]
    

