about summary refs log tree commit diff
path: root/others/dict/dict.py
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-07 21:35:40 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-07 21:35:40 +0700
commit90eb5475115ecf6725f028ec3c39fab95afcb458 (patch)
tree1567f90c5bea4e0c247c228b472268d1adfef93d /others/dict/dict.py
parent1f06cc322606e86918fefa1f707b54264e9ce0a9 (diff)
downloadcp-90eb5475115ecf6725f028ec3c39fab95afcb458.tar.gz
others/dict: Optimize dict.py and add dict.c
Diffstat (limited to 'others/dict/dict.py')
-rwxr-xr-xothers/dict/dict.py10
1 files changed, 3 insertions, 7 deletions
diff --git a/others/dict/dict.py b/others/dict/dict.py
index 59724cd..76b8414 100755
--- a/others/dict/dict.py
+++ b/others/dict/dict.py
@@ -1,16 +1,12 @@
 #!/usr/bin/env python3
 
+from itertools import islice
 from bisect import bisect_left as bisect
 
-words = []
-
 
 with open('dict.inp') as fi, open('dict.out', 'w') as fo:
-    for _ in range(int(fi.readline())):
-        w = fi.readline().strip()
-        i = bisect(words, w)
-        if i == len(words) or w != words[i]:
-            words.insert(i, w)
+    words = list(islice(fi, int(fi.readline())))
+    words.sort()
 
     for _ in range(int(fi.readline())):
         s = fi.readline().strip()