Calculating the similarity of two lists

前端 未结 6 1389
野趣味
野趣味 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:06

    Unless im missing the point.

    from __future__ import division
    
    def similar(x,y):
        si = 0
        for a,b in zip(x, y):
            if a == b:
                si += 1
        return (si/len(x)) * 100
    
    
    if __name__ in '__main__':
        a = [1,8,3,9,4,9,3,8,1,2,3] 
        b = [1,8,1,3,9,4,9,3,8,1,2,3]
        result = similar(a,b)
        if result is not None:
            print "%s%s Similar!" % (result,'%')
    

提交回复
热议问题