fork(1) download
  1. import difflib
  2.  
  3. def matches(first_string,second_string):
  4. s = difflib.SequenceMatcher(None, first_string,second_string)
  5. match = [first_string[i:i+n] for i, j, n in s.get_matching_blocks() if n > 0]
  6. return match
  7.  
  8. first_string = "this is a sample string"
  9. second_string = "this is also a sample string"
  10. print matches(second_string, first_string )
Success #stdin #stdout 0.04s 8560KB
stdin
Standard input is empty
stdout
['this is', ' a sample string']