mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added abbrev
This commit is contained in:
parent
b1a2b87ed3
commit
10a65f7399
20
src/utils.py
20
src/utils.py
@ -63,4 +63,24 @@ def htmlToText(s):
|
||||
x.feed(s)
|
||||
return x.getText()
|
||||
|
||||
def eachSubstring(s):
|
||||
for i in range(1, len(s)+1):
|
||||
yield s[:i]
|
||||
|
||||
def abbrev(strings):
|
||||
d = {}
|
||||
for s in strings:
|
||||
for abbreviation in eachSubstring(s):
|
||||
if abbreviation not in d:
|
||||
d[abbreviation] = s
|
||||
else:
|
||||
d[abbreviation] = None
|
||||
removals = []
|
||||
for key in d:
|
||||
if d[key] is None:
|
||||
removals.append(key)
|
||||
for key in removals:
|
||||
del d[key]
|
||||
return d
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user