commit 63838ada2f96be79473763307350400fe455ab4c
parent 78820229fb30ca6c4634a1f73fd70552a0dcf719
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Wed, 26 Aug 2015 23:00:03 +0200
defaultdict
Diffstat:
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/graph.py b/graph.py
@@ -2,10 +2,9 @@
import sys
from common import vowels, is_pref, semivowels, fem
+from collections import defaultdict
-# TODO use defaultdict
-
-g = {}
+g = defaultdict(lambda: defaultdict(lambda: set()))
def nedd(myg):
n = 0
@@ -15,7 +14,7 @@ def nedd(myg):
return n
def tred(myg):
- g2 = {}
+ g2 = defaultdict(lambda: defaultdict(lambda: set()))
tos_m = set()
tos_f = set()
for f in myg.keys():
@@ -44,10 +43,6 @@ def tred(myg):
if t not in myg.keys():
continue
for w in myg[f][t]:
- if f not in g2.keys():
- g2[f] = {}
- if t not in g2[f].keys():
- g2[f][t] = set()
g2[f][t].add(w)
return g2
@@ -62,10 +57,6 @@ for l in sys.stdin.readlines():
t = ((p[-2][-2:] if p[-2][-1] in semivowels else p[-2][-1]) if p[-1][0] in vowels else ((p[-3][-2:] if p[-3][-1] in
semivowels else p[-3][-1]) + p[-2])) + p[-1]
# print ("%s : %s -> %s" % (w, f, t))
- if f not in g.keys():
- g[f] = {}
- if t not in g[f].keys():
- g[f][t] = set()
addit = True
for ws in g[f][t]:
# if one is prefix of us, give up