duire

french missing verbs with prefix forms
git clone https://a3nm.net/git/duire/
Log | Files | Refs

calcpref.py (545B)


      1 #!/usr/bin/python3 -O
      2 # -*- encoding: utf-8
      3 
      4 import operator
      5 import sys
      6 
      7 words = set()
      8 
      9 for l in sys.stdin.readlines():
     10     words.add(l.rstrip())
     11 
     12 myprefs = {}
     13 
     14 for w in words:
     15     for i in range(len(w)):
     16         w2 = w[i:]
     17         if i == 0 or i == len(words):
     18             continue
     19         if w2 in words:
     20             p = w[:i]
     21             if p not in myprefs.keys():
     22                 myprefs[p] = 0
     23             myprefs[p] += 1
     24 
     25 sorted_x = sorted(myprefs.items(), key=operator.itemgetter(1))
     26 for (t, v) in sorted_x:
     27     print("%s %s" % (t, v))
     28