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.

271 questions
0
votes
1 answer

Find the closest match between two string variables using difflib

))Hi all, I would like to find the closest match between two string variables using difflib, this is my case... varA = 'plainmountain' varB = 'skymountain' newVarA = 'piaimauntain' I would like to difflib to find the closest match in VarA and VarB…
Natysiu16
  • 146
  • 3
  • 11
0
votes
2 answers

Finding the diff of two lists of strings

I'm trying to find a diff (longest common subsequences) between two lists of strings. I'm guessing difflib could be useful here, but difflib.ndiff annotates the output with -, +, etc. For instance from difflib import ndiff t1 = 'one 1\ntwo 2\nthree…
Kar
  • 5,373
  • 6
  • 47
  • 79
0
votes
1 answer

Subtract List B from List A, but keeping the List A index and using difflib string similarity

I need some help with Python. This is not the classic subtract List B from List A to make List C. Instead I would like to look at the indexes of the items in List A (city names in a single word) that are not in List B, and store them into a new List…
litu16
  • 163
  • 4
  • 13
0
votes
1 answer

Trying to compare files opened using 'with open...' in Python 2.4 gives a SyntaxError

How can I compare two files in Python 2.4.4? The files could be different lengths. We have Python 2.4.4 on our servers. I would like to use the difflib.unified_diff() function but I can't find examples that work with Python 2.4.4. All the versions…
0
votes
1 answer

Programmatically figuring out if translated names are equivalent

I'm trying to see if two translated names are equivalent. Sometimes the translation will have the names ordered differently. For example: >>> import difflib >>> a = 'Yuk-shing Au' >>> b = 'Au Yuk Sing' >>> seq=difflib.SequenceMatcher(a=a.lower(),…
David542
  • 96,524
  • 132
  • 375
  • 637
0
votes
1 answer

Python difflib reporting unwanted difference

I am trying to compare two sequences using difflib.Differ(). However, I am observing some unwanted differences which I am not able to understand. Can someone please explain this behavior and how this can be resolved? import difflib a = "abc-123…
sarbjit
  • 3,262
  • 9
  • 30
  • 52
0
votes
1 answer

Comparing two HTML files and return the HTML tags that differ between the two

I am writing a web monitoring script using python that will look at a archived version of the page, compare it to the current, online version, and notify me if there are any changes. I have the basics of this working, but am running into a problem…
Butters
  • 875
  • 1
  • 8
  • 27
0
votes
1 answer

Observe changes in a text?

I have the following problem. I changed some parts of a online articel. Afterwards, other people start editing this online articel. Now I'm trying program a code with python that identify, if the guys after me, changed something (and how much,…
0
votes
2 answers

Python program to compare two files for showing the difference

I have the following code to compare two files. I would like this program run if I point them to files which are as big as 4 or 5 MB. When I do that, the prompt cursor in python console just blinks, and no output is shown. Once, I ran it for the…
MiniGunnR
  • 4,590
  • 5
  • 33
  • 54
0
votes
2 answers

Django two files upload for difference

I have already posted in https://stackoverflow.com/questions/26776003/how-to-use-htmldiff-in-django-to-show-difference-of-two-uploaded-files However, I want to know if there is an easy way to upload a couple of files and submit which shows the…
MiniGunnR
  • 4,590
  • 5
  • 33
  • 54
0
votes
1 answer

Python difflib with regex

I would like to compare a string A with a regex R. A = u'Hi my friend, my name is Julio' R = r'Hi\s+my\s+friend,\s+my\s+name\s+is([A-Za-z]+)' At this time I can easily know if the syntax is good thanks to re.matchand re.search. Now I would like to…
Julio
  • 2,253
  • 4
  • 23
  • 49
0
votes
1 answer

Python dataframes

I have a dataframe (df) and trying to append data to a specific row Index Fruit Rank 0 banana 1 1 apple 2 2 mango 3 3 Melon 4 The goal is to compare the Fruit at Rank 1 to each rank and then append the…
BlackHat
  • 688
  • 1
  • 9
  • 21
0
votes
1 answer

Efficient data structure for searching a dictionary of words in python using difflib?

I am trying to write a spellchecker and I wanted to use difflib to implement it. Basically I have a list of technical terms that I added to the standard unix dictionary (/usr/share/dict/words) that I'm storing in a file I call dictionaryFile.py. I…
user3058197
  • 1,012
  • 7
  • 20
0
votes
1 answer

Compare two phrases using WordNet?

I am trying to compare the semantic of two phrases. In Python I am using nltk and difflib. First I am removing the stop words from the phrases, then I am using WordNetLemmatizer and PorterStemmer to normalise the words then I am comparing the rest…
Rami
  • 6,898
  • 16
  • 61
  • 98
0
votes
1 answer

Find equal sequence from 10 lines strings

I'm trying find longest common sequence from text file, which contains string lines. Output should be also text file with align lines like in example: find sequence - efghijk output file: abcdefghijklmno dfefghijkrumlp swrefghijkawsfce …