我在Python中有一个如下所示的列表:
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']
我希望它看起来像这样:
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']
如何做到这一点?如何将所有元素组合成一个元素?
由于
答案 0 :(得分:2)
根据您的最新修改,您需要根据,
拆分列表,以便您可以
print [item for items in Temp for item in items.split(",")]
<强>输出强>
['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']
注意:根据PEP-0008,Python样式圣经,不鼓励使用带有首字母大写字母的变量名称。