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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -