|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Block111 于 2017-9-9 16:30 编辑
需要按照最后一列排序;怎么只排序四位数的几项,后面都不能排序;
#排序
[b]def select_sort(array):
p=list(open(array+'.txt','r'))
t_array=[]
for each in p:
l=int(each.split(',',4)[4])
t_array.append(each)
for i in range(len(t_array)-1):
min = int(i)
for j in range(i+1, len(t_array)):
if t_array[j] < t_array[min]:
min = int(t_array[j])
p[i], p[min] = p[min], p[i]
file=open(array+'x.txt','w')
file.writelines(p)
file.close()
排序后结果:
140301-MSHA-S1303P,1,GR-A,HP140X8,2264
140301-MSHA-S1304P,1,GR-A,HP140X8,2182
140301-MSHA-S1305P,1,GR-A,HP140X8,2182
140301-MSHA-S1312P,1,GR-A,HP140X8,7800
140301-MSHA-S1313P,1,GR-A,HP140X8,7800
140301-MSHA-S1314P,1,GR-A,HP140X8,7800
140301-MSHA-S1315P,1,GR-A,HP140X8,7800
140301-MSHA-S1316P,1,GR-A,HP140X8,7800
140301-MSHR-S1300S,1,GR-A,HP140X8,2182
140301-MSHR-S1301S,1,GR-A,HP140X8,2182
140301-MSHR-S1302S,1,GR-A,HP140X8,2264
140301-MSHR-S1307S,1,GR-A,HP140X8,7800
140301-MSHR-S1308S,1,GR-A,HP140X8,7800
140301-MSHR-S1309S,1,GR-A,HP140X8,7800
140301-MSHR-S1310S,1,GR-A,HP140X8,7800
140301-MTTA-S589P,1,GR-A,HP140X8,7800
140301-MTTA-S590P,1,GR-A,HP140X8,7800
140301-MTTA-S591P,1,GR-A,HP140X8,7800
140301-MTTA-S592P,1,GR-A,HP140X8,7800
140301-MTTR-S584S,1,GR-A,HP140X8,7800
140301-MTTR-S585S,1,GR-A,HP140X8,7800
140301-MTTR-S586S,1,GR-A,HP140X8,7800
140301-MTTR-S594S,1,GR-A,HP140X8,7800
140301-WSH-S1306S,1,GR-A,HP140X8,7800
140301-WSH-S1311S,1,GR-A,HP140X8,7800
140301-WSH-S1317P,1,GR-A,HP140X8,7800
140301-WTT-S1318S,1,GR-A,HP140X8,650
140301-WTT-S1319S,1,GR-A,HP140X8,650
140301-WTT-S1320S,1,GR-A,HP140X8,725
140301-WTT-S1321P,1,GR-A,HP140X8,725
140301-WTT-S1322P,1,GR-A,HP140X8,650
140301-WTT-S1323P,1,GR-A,HP140X8,650
- def select_sort(array):
- p=list(open(array+'.txt','r'))
- t_array=[]
- for each in p:
- l=int(each.split(',',4)[4])
- t_array.append([l,each])
-
- t_array.sort()
-
- content = ''
- for each in t_array:
- content += each[1]
-
-
- file=open(array+'x.txt','w')
- file.writelines(content)
- file.close()
- select_sort('1111')
复制代码
|
|