Python: merge nested lists

Use the power of the zip function and list comprehensions:

list1 = [('a', ),
        ('b', 'c'),
        ('d', 'e'),
        ('f', 'g', 'h') ]

list2 = [('p', 'q'),
        ('r', 's'),
        ('t', ),
        ('u', 'v', 'w') ]

print [a + b for a, b in zip(list1, list2)]

Leave a Comment