efficient list merging

T.Meyarivan self at meyarivan.org
Wed Sep 4 10:45:42 EDT 2002


> Here's an example:
> 
> lol1 = [['a'], ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i', 'j']]
> lol2 = [['d', 'e', 'f'], ['k', 'l', 'm'], ['d'], ['f', 'g'], ['a']]
> 
> I want a function which returns
> 
> mergelol = [['a'], ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i',
> 'j'], ['k', 'l', 'm'], ['d']]

# lista and listb are the lists of lists

def merge(lista, listb):
    x  = {}
    map(x.setdefault, map(tuple, lista + listb))

    return x.keys()






More information about the Python-list mailing list