- 论坛徽章:
- 1
|
- [winway@s208 test]$ cat urfile
- 9N 11N 9T 13N
- 9N1 11N1 9T1 13N1
- 9N2 11N2 9T2 13N2
- 9N3 11N3 9T3 13N3
- 9N4 11N4 9T4 13N4
- 9N5 11N5 9T5 13N5
- [winway@s208 test]$ ./test.py
- 9N 9T 11N 13N
- 9N1 9T1 11N1 13N1
- 9N2 9T2 11N2 13N2
- 9N3 9T3 11N3 13N3
- 9N4 9T4 11N4 13N4
- 9N5 9T5 11N5 13N5
- [winway@s208 test]$ cat test.py
- #! /bin/env python
- # -*- coding: utf-8 -*-
- #
- is_1stline = 1
- order_map = {}
- def mycmp(x, y):
- xn = int(x[:-1])
- yn = int(y[:-1])
- return cmp(xn, yn)
- with open('urfile', 'r') as f:
- for l in f:
- li = l.split()
- if is_1stline:
- is_1stline = 0
- tmp_dict = {}
- for n, r in enumerate(li):
- tmp_dict[r] = n
- li.sort(mycmp)
- for n, r in enumerate(li):
- order_map[n] = tmp_dict[r]
- print ' '.join(li)
- else:
- for i in xrange(len(li)):
- print li[order_map[i]],
- print
复制代码 |
|