Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def replaceAccents(l):
"""
replace greek accents
"""
l = l.lower()
rDict = {'ά':'α','ό':'ο','ύ':'υ','ϋ':'υ','ΰ':'υ','έ':'ε','ί':'ι',
'ϊ':'ι','ΐ':'ι','ή':'η','ώ':'ω','ς':'σ'}
retStr = ''
for x in l:
retStr += (x if x not in rDict else rDict[x])
return(retStr)
def isin(letters,string):
"""
returns True if all letters are in string
and False otherwise
"""
for l in letters:
if l not in string:
return(False)
return(True)
def minl(letters):
"""
prints words that have all the letters in letters
and tries to locate the smallest one
"""
with open('el_GR.dic','r',encoding = 'iso-8859-7') as lexiko:
#dictionary from
#https://raw.githubusercontent.com/LibreOffice/dictionaries/master/el_GR/el_GR.dic
lexeis = lexiko.read().splitlines()
minword = " "*30
for l in lexeis:
if l.upper() == l:
continue
if isin(remaining,replaceAccents(l.lower())):
if len(l)<=len(minword)+2:
print(l)
if len(l)<=len(minword):
print(l)
minword = l
return(minword)
allLetters = ['α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν',
'ξ','ο','π','ρ','σ','τ','υ','φ','χ','ψ','ω']
tillNow = input("Φράση μέχρι τώρα...>")
remaining = [x for x in allLetters if x not in replaceAccents(tillNow.lower())]
print("".join(remaining))
print("Min word is :" + minl(remaining))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.