문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top