python difflib print only matches part between two strings
python difflib print only matches part between two strings I am totally new with python, and I need some help about difflib. I tried read the documentation, but for me is not easy to understand the docs. I would like compare two strings, and I want the output is only the matches prefix-part between two string (do not print the differences) . Example: t1 = "hello my name is Tom" t2 = "hello his name is Sawyer" expected output is: "hello " I tried by following approaches, but the output is not what I want because it print the output as array and also print not only matches part: #!/usr/bin/python import difflib t1 = "hello my name is Tom" t2 = "hello his name is Sawyer" seq = difflib.Differ() seq = seq.compare(t1,t2) print list(seq) other example-2: t1 = "20180628-153020" t2 = "20180628-173020" expected output printout: "20180628-1" and the suffix "3020" even both part of string matches the position...
