- 论坛徽章:
- 0
|
我做的,方法有点笨,不知道是不是你想要的要求.
code='''2009-06-24 00:00:00,0802,0000002001,0
2009-06-24 00:00:00,1201,0000002001,0
2009-06-24 00:00:00,1452,0000002001,0
2009-06-24 00:00:00,1755,0000002001,0
2009-06-24 00:00:00,1800,0000002001,0
2009-06-25 00:00:00,0741,0000002001,0
2009-06-25 00:00:00,1202,0000002001,0
2009-06-25 00:00:00,1447,0000002001,0
2009-06-25 00:00:00,1800,0000002001,0
2009-06-26 00:00:00,0746,0000002001,0
2009-06-26 00:00:00,1200,0000002001,0
2009-06-26 00:00:00,1310,0000002001,0
2009-06-26 00:00:00,1431,0000002001,0
2009-06-26 00:00:00,1801,0000002001,0
2009-06-27 00:00:00,0803,0000002001,0
2009-06-27 00:00:00,1213,0000002001,0
2009-06-27 00:00:00,1427,0000002001,0
2009-06-27 00:00:00,1800,0000002001,0'''
newcode=code.replace(' ',',')
codelist=newcode.split('\n')
i=0
finalcodelist=[]
while i<len(codelist):
temp=codelist[i].split(',')
if temp[0] in finalcodelist:
i+=1
finalcodelist.append(temp[2])
continue
finalcodelist.append(temp[0])
finalcodelist.append(temp[3])
finalcodelist.append(temp[2])
i+=1
tar=','.join(finalcodelist)
print tar.replace(',2009','\r\n2009') |
最后结果:
>>>
2009-06-24,0000002001,0802,1201,1452,1755,1800
2009-06-25,0000002001,0741,1202,1447,1800
2009-06-26,0000002001,0746,1200,1310,1431,1801
2009-06-27,0000002001,0803,1213,1427,1800
>>> |
|