How to merge 4 lists into 1 in python -


my code like

testgraph=open(input("enter file name:")) line in testgraph:   temp=line.split() 

and out put like

['0', '1'] ['2', '1'] ['0', '2'] ['1', '3'] 

and want make them into

[['0', '1'],['2', '1'],['0', '2'],['1', '3']] 

could me?

you can use itertools.chain() flat lists 1 list.

>>> cmd = ['ls', '/tmp'] >>> numbers = range(3) >>> itertools.chain(cmd, numbers, ['foo', 'bar']) <itertools.chain object @ 0x0000000003943f28> >>> list(itertools.chain(cmd, numbers, ['foo', 'bar'])) ['ls', '/tmp', 0, 1, 2, 'foo', 'bar'] 

but if want have list of lists, appending list choice.

testgraph=open(input("enter file name:")) result = [] line in testgraph:   result.append(line.split()) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -