Merge two lists with labels
Question: I want to merge two sorted lists into a new sorted lists, but I want to
include labels into the new list to see which list was the origin of each
value.

So far that's my code:

    
    
    l1 = [1, 40, 90, 104]
    l2 = [5, 20, 70, 85, 230]
    test = [(i, "l1") for i in l1 ] + [(i, "l2") for i in l2]
    test.sort() 
    print test
    
     [(1, 'l1'), (5, 'l2'), (20, 'l2'), (40, 'l1'), (70, 'l2'), (85, 'l2'), (90, 'l1'), (104, 'l1'), (230, 'l2')]
    

I'm using Python 2.7.6. Is there a faster way to do this? Because my lists
will be very long (hundreds of thousand)


Answer: I usually use itertools for this kind of thing

    
    
    import itertools
    l1 = [1, 40, 90, 104]
    l2 = [5, 20, 70, 85, 230]
    
    test = zip(l1,itertools.repeat('li')) + zip(l2,itertools.repeat('l2'))
    

