OSDN Git Service

modified: src/padarea.c
[kp123/kp123.git] / data / sort.py
1 #!/usr/bin/env python3
2
3 import sys
4
5 if len(sys.argv) < 2:
6         print("usage: %s filename" % sys.argv[0])
7         sys.exit(0)
8
9 l = []
10 f = sys.argv[1]
11 fi = open(f, 'r')
12 for i in fi.readlines():
13         if len(i) < 3:
14                 continue
15         if i[1] == 'A' and i[3] == 'A':
16                 print(i)
17                 print(ord(i[0]))
18         if ord(i[0]) == 0xFEFF:
19                 i = i[1:]
20                 print(i)
21         if i[0:2] == "\xFE\xFF": i = i[2:]
22         l.append(i)
23 fi.close()
24
25 def my_cmp(a, b):
26         print("mycmp")
27         for i in range(0, min(len(a), len(b))):
28                 if(i == 1): continue
29                 if(a[i] > b[i]): return 1
30                 if(a[i] < b[i]): return -1
31         return 0
32
33 def cmp_to_key(mycmp):
34         'Convert a cmp= function into a key= function'
35         class K(object):
36                 def __init__(self, obj, *args):
37                         self.obj = obj
38                 def __lt__(self, other):
39                         return mycmp(self.obj, other.obj) < 0
40                 def __gt__(self, other):
41                         return mycmp(self.obj, other.obj) > 0
42                 def __eq__(self, other):
43                         return mycmp(self.obj, other.obj) == 0
44                 def __le__(self, other):
45                         return mycmp(self.obj, other.obj) <= 0  
46                 def __ge__(self, other):
47                         return mycmp(self.obj, other.obj) >= 0
48                 def __ne__(self, other):
49                         return mycmp(self.obj, other.obj) != 0
50                         return K
51
52 print("sort start")
53 l.sort(key=lambda s: str.lower(s.replace(s[1], "")))
54 print("sort end")
55 fo = open(f + "_sorted", 'w')
56 for i in l:
57         fo.write(i)
58 fo.close()