python - Fuzzy match ranking -
i fuzzy matched list of movie titles , compiled them list of each comparison along match values:
>>> fuzzy_matches [(['white warrior (alpha video)'], ['white warrior (alpha video)'], 100), (['white warrior (alpha video)'], ['white warrior (digiview entertainment)'], 63), (['white warrior (alpha video)'], ['white warrior (platinum)'], 78), (['white warrior (alpha video)'], ['white warrior (platinum) / david , goliath'], 63), (['white warrior (alpha video)'], ['white warrior (platinum) / duel of champions'], 61)]...etc i want add match values each title output this:
>>>([white warrior (alpha video)], 248), ['white warrior 2 (digiview entertainment)'], 390), etc... i have tried several implementations utilizing slices it's ugly.
(not exact code ugliness):
for x in range(len(fuzzed)):     y in fuzzed(len(fuzzed)):  big_dict[fuzzy_matches[55][0][0]]=fuzzy_matches[55][2] + fuzzy_matches[56][3]... what more efficient way accomplish this?
you can use dict store results want , , @ end if want list of tuples , can use dict.items() (python 3.x ) that.
example -
>>> fuzzy_matches = [(['white warrior (alpha video)'], ['white warrior (alpha video)'], 100), (['white warrior (alpha video)'], ['white warrior (digiview entertainment)'], 63), (['white warrior (alpha video)'], ['white warrior (platinum)'], 78), (['white warrior (alpha video)'], ['white warrior (platinum) / david , goliath'], 63), (['white warrior (alpha video)'], ['white warrior (platinum) / du el of champions'], 61)] >>> >>> fuzzy_dict = {} >>> in fuzzy_matches: ...     if i[0][0] not in fuzzy_dict: ...             fuzzy_dict[i[0][0]] = 0 ...     fuzzy_dict[i[0][0]] += i[2] ... >>> fuzzy_dict {'white warrior (alpha video)': 365} >>> list(fuzzy_dict.items()) [('white warrior (alpha video)', 365)] you not need list(...) @ end if using python 2.x .
Comments
Post a Comment