Question

I have a list in Python that looks like this:

Temp = ['H,test,0,04/09/2014,15:19:35,15:28:30,0.07,0,0,avo,1', 'N,2,1,240.00,30.00,1,3,1,,,,,,,', 'K,0.18,,,,', 'D,,,,,,,,,15,', 'U,35P019,000000,ST,5,U,00,Y,0000,,', 'T,1,Disk,WH,All Element,FL,72,0.062,0.079,0.070,PASS']

I'd like it to look like this:

Temp = ['H','test','0','04/09/2014','15:19:35','15:28:30','0.07','0','0','avo','1','N','2','1','240.00','30.00','1','3','1','','','','','','','', 'K','0.18','','','','','D','','','','','','','','','15','','U','35P019','000000','ST','5','U','00','Y','0000','','','T','1','Disk','WH','All Element','FL','72','0.062','0.079','0.070','PASS']

How can this be done? How can all elements be combined to one element?

Thanks

Était-ce utile?

La solution

As per your latest edit, you need to split the list based on ,, so you can do

print [item for items in Temp for item in items.split(",")]

Output

['H',
 'test',
 '0',
 '04/09/2014',
 '15:19:35',
 '15:28:30',
 '0.07',
 '0',
 '0',
 'avo',
 '1',
 'N',
 '2',
 '1',
 '240.00',
 '30.00',
 '1',
 '3',
 '1',
 '',
 '',
 '',
 '',
 '',
 '',
 '',
 'K',
 '0.18',
 '',
 '',
 '',
 '',
 'D',
 '',
 '',
 '',
 '',
 '',
 '',
 '',
 '',
 '15',
 '',
 'U',
 '35P019',
 '000000',
 'ST',
 '5',
 'U',
 '00',
 'Y',
 '0000',
 '',
 '',
 'T',
 '1',
 'Disk',
 'WH',
 'All Element',
 'FL',
 '72',
 '0.062',
 '0.079',
 '0.070',
 'PASS']

Note: According to PEP-0008, Python Style Bible, using a variable name with an initial capital letter is not encouraged.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top