I have a two-dimensional list. I would like to get the two elements from list_j, i.e. the two lists that have the highest agreement with list_g. I've tried something, but how do I get the two lists that match the most?
list_j = [[100,2,3], [4,98,99], [5,99,98]]
list_g = [100,99,98]
import difflib
list_ratio = []
for element_g in list_j:
sm=difflib.SequenceMatcher(None,element_g,list_g)
list_ratio.append(sm.ratio())
print(list_ratio)
[OUT] [0.3333333333333333, 0.3333333333333333, 0.6666666666666666]
In this example, the last element then 1 or 2 has the most similarity. How could I get them?
question from:https://stackoverflow.com/questions/65644038/get-only-the-two-lists-with-the-most-similarity