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
Post a Comment