Python Forum
find and group similar words with re?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find and group similar words with re?
#3
A similar library to what Gribouillis posted is TheFuzz(eailer called fuzzywuzzy).
Test.
from thefuzz import fuzz

list1 = ["Augsburg II", "Turkgucu Munchen", "Bayern II"]
list2 = ["Augburg II", "Turkgucu Munich", "Baye II"]
>>> fuzz.ratio(list1[0], list2[0])
95
>>> fuzz.ratio(list1[1], list2[1])
90
>>> fuzz.ratio(list1[2], list2[2])
88
Then can decided what ratio is ok to make it similar enuff,let say that choose 90.
from thefuzz import fuzz

list1 = ["Augsburg II", "Turkgucu Munchen", "Bayern II"]
list2 = ["Augburg II", "Turkgucu Munich", "Baye II"]


list3 = []
for l1, l2 in zip(list1, list2):
    if fuzz.ratio(l1, l2) >= 90:
        #print(f'{l1} = {l2}')
        list3.append(f'{l1} = {l2}')

print(list3)
Output:
['Augsburg II = Augburg II', 'Turkgucu Munchen = Turkgucu Munich']
cartonics likes this post
Reply


Messages In This Thread
RE: find and group similar words with re? - by snippsat - Oct-27-2023, 01:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,398 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,886 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Sum similar items tester_V 3 2,029 Jun-29-2021, 06:58 AM
Last Post: tester_V
  Trying to find first 2 letter word in a list of words Oldman45 7 3,846 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  Check text contains words similar to themes/topics (thesaurus) Bec 1 36,195 Jul-28-2020, 04:17 PM
Last Post: Larz60+
  Voynich search engine in python using dashes & dot totals to find Italian words Pleiades 3 3,580 Oct-10-2019, 10:04 PM
Last Post: Pleiades
  Create a function to find words of certain length ag4g 2 4,135 Apr-21-2019, 06:20 PM
Last Post: BillMcEnaney
  Python: if 'X' in 'Y' but with two similar strings as 'X' DreamingInsanity 6 3,934 Feb-01-2019, 01:28 PM
Last Post: buran
  Similar to Poker bluekade5050 1 36,150 Nov-14-2018, 04:46 PM
Last Post: j.crater
  Compare all words in input() to all words in file Trianne 1 2,801 Oct-05-2018, 06:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020