Questions tagged [difflib]

A python module, provides tools for computing and working with differences between sequences, especially useful for comparing text. Includes functions that produce reports using several common difference formats.

A python module which provides classes and functions for comparing sequences. It can be used for example, for comparing files, and can produce difference information in various formats, including HTML and context and unified diffs.

341 questions
4
votes
3 answers

How to compare two models to be rendered with Markdown using Django?

What is the best way to check for changes (edited/added/deleted text) in a post between two post's versions (original and edited one)? I am using Markdown so I am not sure if using difflib.HtmlDiff is a good idea. My goal is to mark with a green…
Pompeyo
  • 1,459
  • 3
  • 18
  • 42
3
votes
2 answers

difflib returns different ratio depending on order of sequences

Does anyone know why these two return different ratios. >>> import difflib >>> difflib.SequenceMatcher(None, '10101789', '11426089').ratio() 0.5 >>> difflib.SequenceMatcher(None, '11426089', '10101789').ratio() 0.625
iiijjjiii
  • 33
  • 1
  • 3
3
votes
1 answer

How to highlight more than two characters per line in difflibs html output

I am using difflib.HtmlDiff to compare two files. I want the differences to be highlighted in the outputted html. This already works when there are a maximum of two different chars in one line: a = "2.000" b = "2.120" But when there are more…
Lars Bilke
  • 4,940
  • 6
  • 45
  • 63
3
votes
4 answers

Python closest match between two string columns

I am looking to get the closest match between two columns of string data type in two separate tables. I don't think the content matters too much. There are words that I can match by pre-processing the data (lower all letters, replace spaces and stop…
Daniel
  • 373
  • 1
  • 10
3
votes
3 answers

Python difflib with regular expressions

Can I use regular expressions in difflib? Specifically, I'd like to do: difflib.context_diff(actual, gold) Where actual is: [master 92a406f] file modified and gold is: \[master \w{7}\] file modified
Jonathan
  • 83
  • 1
  • 6
3
votes
1 answer

Using the difflib.HtmlDiff class - showing single chars

I am using the difflib.HtmlDiff class, calling the function using two sets of text (HTML from websites), however when it makes the table html_diff = difflib.HtmlDiff() print html_diff.make_table(previous_contents, fetch_url.page_contents) however…
Wizzard
  • 12,582
  • 22
  • 68
  • 101
3
votes
3 answers

How to highlight (only) word errors using difflib?

I'm trying to compare the output of a speech-to-text API with a ground truth transcription. What I'd like to do is capitalize the words in the ground truth which the speech-to-text API either missed or misinterpreted. For Example: Truth: The quick…
3
votes
1 answer

Group Unique Values on Unique Value with most occurence Python

Below is a sample of my df name A S BITO A S KIGEL A S NATURENERGI A S NATURENERGIE A S NATURENERGIE A S P BU SERVICE POWER P A S P BU SERVICE POWER P A S P BU SERVICE POWER PETER GMBH A S P GMBH A RESE LAND A RITTER WITH SA A RITTER WITH SA …
A2N15
  • 595
  • 4
  • 20
3
votes
3 answers

Python sequence matcher with custom matching function

I have two lists and I want to find the matching elements using python difflib/sequence matcher, and it goes like this: from difflib import SequenceMatcher def match_seq(list1,list2): output=[] s = SequenceMatcher(None, list1, list2) …
hmghaly
  • 1,411
  • 3
  • 29
  • 47
3
votes
1 answer

Comparing lists in python by difflib modul

I am trying out the difflib library. I have two lists: L_1 and L_2 containing strings. I want to know, if those sequences are similar (order is not important). L_1 = ["Bob", "Mary", "Hans"] L_2 = ["Bob", "Marie", "Háns"] should be ok. But L_1 =…
Aufwind
  • 25,310
  • 38
  • 109
  • 154
3
votes
1 answer

Finding Close String Matches - valuing sub string word matches higher

I'm trying to find close string matches (context - searching for a discord user from user input). Atm, I'm trying out the difflib. It works ok, but seems to return some funny results sometimes. Eg. if someone's name contains a word, searching that…
Shuri2060
  • 729
  • 6
  • 21
3
votes
1 answer

How to understand/use the Python difflib output?

I am trying to make comprehensive diff that compares command line output of two programs. I used difflib and came up with this code: from difflib import Differ from pprint import pprint import sys def readable_whitespace(line): return…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
3
votes
2 answers

How to fuzzy match movie titles with difflib and pandas?

I have 2 lists of potentially overlapping movie titles, but possibly written in a different form. They are in 2 different dataframes from pandas. So I have tried to use the map() function with the fuzzywuzzy library like so: df1.title.map(lambda x:…
Bastian
  • 5,625
  • 10
  • 44
  • 68
3
votes
1 answer

Comparing two files using difflib in python

I am trying to compare two files using difflib. After comparing I want to print "No Changes" if no difference detected. If difference is their in some lines. I want to print those line. I tried like this: with open("compare.txt") as f,…
Krishna
  • 45
  • 2
  • 6
3
votes
1 answer

Cannot Import Difflib in python. How can I solve?

I am trying to use difflib but it's giving an import error. Can someone please help? Here is the traceback : Traceback (most recent call last): File "", line 1, in File "difflib.py", line 1, in from difflib import…
silent_dev
  • 1,566
  • 3
  • 20
  • 45