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
0
votes
1 answer

Compare Two Different JSON In Python Using Difflib, Showing Only The Differences

I am trying to compare 2 different pieces of (Javascript/JSON) code using difflib module in Python 3.8, {"message": "Hello world", "name": "Jack"} and {"message": "Hello world", "name": "Ryan"} Problem: When these 2 strings are prettified and…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
0
votes
0 answers

I can't get the closest matches right here...How can i implement difflib right here in a right order?

When i am typing "rainn", i want to get results for "rain".Here's what i've tried - but there is no success import mysql.connector from difflib import get_close_matches con = mysql.connector.connect( user = , password = , host =…
ElMuchacho
  • 300
  • 1
  • 12
0
votes
1 answer

Iteratively matching substrings and then removing matches

I have a list of N strings with patterns in that I would like to match. I am doing this using the difflib library: from difflib import SequenceMatcher def longestSubstring(str1,str2): seqMatch = SequenceMatcher(None,str1,str2) match =…
d-man
  • 476
  • 4
  • 24
0
votes
2 answers

How to get matches for some words in a list from another list?

I have two lists, I want to compare one list with the other and get all the close matches as output for each word. For example: a = ['apple','python','ice-cream'] b = ['aaple','aple','phython','icecream','cat','dog','cell'] so when I pass the list…
Ramya T
  • 53
  • 1
  • 6
0
votes
0 answers

How to find path_similarity for lemmas in spanish?

When I try to find path_similarity or whether two English words are synonyms, I am able to execute for English, but when I try the same for Spanish, it shows an error. Please find the attached the screenshot:
0
votes
1 answer

Get more similar word based on a Pandas DataFrame and a List

I want to return a new column on my dataframe with the word more similar to my pandas column value (in this case col1). My actual dataframe is: And I have the following list: ['Product_A1', 'Product_B1', 'Product_C'] And my output should be: For…
Pedro Alves
  • 1,004
  • 1
  • 21
  • 47
0
votes
1 answer

Pandas replace strings with fuzzy match in the same column

I have a column in a dataframe that is like this: OWNER -------------- OTTO J MAYER OTTO MAYER DANIEL J ROSEN DANIEL ROSSY LISA CULLI LISA CULLY LISA CULLY CITY OF BELMONT CITY OF BELMONT CITY Some of the names in my data frame are…
0
votes
0 answers

SequenceMatcher unable to distinguish between 'replace' and 'insert'

First example: one = ['billy', 'sally', 'gd', 'kk', 'btb'] two = ['billy', 'sally', 'hh', 'kk', 'ff', 'btb'] opcodes1 = SequenceMatcher(None, one, two).get_opcodes() opcodes2 = SequenceMatcher(None, two, one).get_opcodes() correctly returns the…
Rhys
  • 4,926
  • 14
  • 41
  • 64
0
votes
1 answer

ndiff returns a delta while none exists

I have two log files that I am trying to compare, in bash: $ diff logfile_56.log logfile_57.log returns nothing. However, when I do the following with difflib.ndiff I get the following: import difflib with ('logfile_56.log', 'r') as file_one: …
readytotaste
  • 199
  • 2
  • 4
  • 17
0
votes
1 answer

difflib: comparing a list of keywords with another list and returning ratio

I am trying to compare a list of words with a whole list of sentences using 'difflib'. import pandas as pd from difflib import SequenceMatcher s1 = ['okay', 'bye', 'what is'] # reference keywords s2 = ['okay', 'what', 'dont worry', 'what is my…
Hackerds
  • 1,195
  • 2
  • 16
  • 34
0
votes
1 answer

Can strings be used to generate a comparison report for difflib.HtmlDiff().make_file?

I have 2 lists of strings I want to compare and highlight the differences between them. Code snippet: string1 = "GNBDUFunction=1,TddRadioChannel=1 arfcn 632333, channelBandwidth 20000, frequency , reservedBy [1] = , >>> reservedBy =…
Saad Shan
  • 13
  • 4
0
votes
2 answers

How to get "different" terms in difflib.ndiff?

I'm trying to do a text comparison via the 'difflib' library. I was wondering how to JUST get the terms which are specific to the first string sequence vs the second. Ex: import difflib one = "If rents are received later than five (5)" two = "If…
okeoke
  • 83
  • 1
  • 7
0
votes
0 answers

Python Script to Produce Difference Between Files and Resolve DNS Query for the Output

I wanted to write a python script that gives me the difference between two txt files that contain list of domains. Below is my script that I was able to create. import difflib file1 = open("2.txt").readlines() file2 =…
Data Shark
  • 91
  • 1
  • 1
  • 7
0
votes
1 answer

Clarity about functioning of SequenceMatcher.ratio() function in python

I am confused on how SequenceMatcher.ratio() work. After searching on the Internet, I understand the formula for computing the ratio is: Ratio = 2.0 * M / T where M = number of matches T = total number of elements in both sequence I tried inputing…
0
votes
0 answers

Best search algorithm to find 'similar' strings in excel spreadsheet

I am trying to figure out the most efficient way of finding similar values of a specific cell in a specified column(not all columns) in an excel .xlsx document. The code I have currently assumes all of the strings are unsorted. However the file I am…