diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-11-07 21:35:40 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-11-07 21:35:40 +0700 |
commit | 90eb5475115ecf6725f028ec3c39fab95afcb458 (patch) | |
tree | 1567f90c5bea4e0c247c228b472268d1adfef93d /others/dict/dict.py | |
parent | 1f06cc322606e86918fefa1f707b54264e9ce0a9 (diff) | |
download | cp-90eb5475115ecf6725f028ec3c39fab95afcb458.tar.gz |
others/dict: Optimize dict.py and add dict.c
Diffstat (limited to 'others/dict/dict.py')
-rwxr-xr-x | others/dict/dict.py | 10 |
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() |