From 90eb5475115ecf6725f028ec3c39fab95afcb458 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Mon, 7 Nov 2016 21:35:40 +0700 Subject: others/dict: Optimize dict.py and add dict.c --- others/dict/dict.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'others/dict/dict.py') 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() -- cgit 1.4.1