Python: how do I merge lists to create a nested list -
possible duplicate:
python - merge items of 2 lists list of tuples
how merge 2 lists in nested way?
eg:
list1 = a,b,c list2 = d,e,f i want output be:
[[a,d][b,e][c,f]]
just zip them:
>>> l1 = ['a', 'b', 'c'] >>> l2 = ['d', 'e', 'f'] >>> zip(l1, l2) [('a', 'd'), ('b', 'e'), ('c', 'f')] if need lists, not tuples, in result:
>>> [list(l) l in zip(l1, l2)] [['a', 'd'], ['b', 'e'], ['c', 'f']]
Comments
Post a Comment