Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Moria Doors by Moff
import re
def similar_coeff(w1, w2):
w1 = w1.lower()
w2 = w2.lower()
result = 0
if w1[0] == w2[0]:
result += 10
if w1[-1] == w2[-1]:
result += 10
result += 30 * min(len(w1), len(w2)) / max(len(w1), len(w2))
result += 50 * len(set(w1).intersection(set(w2))) / len(set(w1).union(set(w2)))
return result
def find_word(text):
words = [w.lower() for w in re.findall('\w+', text)]
result, result_sum = '', 0
for w1 in words:
s = sum(similar_coeff(w1, w2) for w2 in words)
if s >= result_sum:
result, result_sum = w1, s
return result
July 25, 2015