fork download
  1. import difflib
  2.  
  3. def solve(s1, s2):
  4. s = difflib.SequenceMatcher(None, s1, s2)
  5. block = s.get_matching_blocks()[0]
  6. if block.a == 0 and block.b == 0:
  7. return block.size / float(len(s1))
  8.  
  9. a = '354575368987943'
  10. b = '354535368987000'
  11. c = '354575368987000'
  12. print solve(a, b)
  13. print solve(a, c)
Success #stdin #stdout 0s 24632KB
stdin
Standard input is empty
stdout
0.266666666667
0.8