Calculating the similarity of two lists

前端 未结 6 1297
野趣味
野趣味 2020-12-24 03:55

I have two lists:

eg. a = [1,8,3,9,4,9,3,8,1,2,3] and b = [1,8,1,3,9,4,9,3,8,1,2,3]

Both contain ints. There is no meaning behind the ints (eg. 1 is not \'cl

6条回答
  •  有刺的猬
    2020-12-24 04:03

    It sounds like edit (or Levenshtein) distance is precisely the right tool for the job.

    Here is one Python implementation that can be used on lists of integers: http://hetland.org/coding/python/levenshtein.py

    Using that code, levenshtein([1,8,3,9,4,9,3,8,1,2,3], [1,8,1,3,9,4,9,3,8,1,2,3]) returns 1, which is the edit distance.

    Given the edit distance and the lengths of the two arrays, computing a "percentage similarity" metric should be pretty trivial.

提交回复
热议问题