Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Moria Doors by UFO665
from string import ascii_lowercase
def likeness(sWord1, sWord2):
res = 0
if sWord1[0] == sWord2[0]:
res += 10
if sWord1[-1] == sWord2[-1]:
res += 10
iLen1, iLen2 = len(sWord1), len(sWord2)
res += min(iLen1, iLen2) / float(max(iLen1, iLen2)) * 30
lstCommonLetters = []
lstUniqueLetters = []
for char in sWord1 + sWord2:
if char in sWord1 and char in sWord2 and char not in lstCommonLetters:
lstCommonLetters.append(char)
if (char in sWord1 and char not in sWord2 or char not in sWord1 and char in sWord2) \
and char not in lstUniqueLetters:
lstUniqueLetters.append(char)
res += len(lstCommonLetters) / float(len(lstCommonLetters + lstUniqueLetters)) * 50
return res
def find_word(message):
sMsg = "".join(s for s in message.lower() if s in ascii_lowercase + " ")
lstWords = sMsg.split()
lstRes = [[likeness(sWord, s) for j, s in enumerate(lstWords) if i != j] for i, sWord in enumerate(lstWords)]
lstAverages = [sum(lst) / float(len(lst)) for lst in lstRes]
index = iMax = 0
for i in range(len(lstAverages)):
if lstAverages[i] >= iMax:
index = i
iMax = lstAverages[i]
return lstWords[index]
March 3, 2016