0

I have a list consisting of some lines.I want to print the line matching word 'good' with highest fuzzyratio.

Problem: Its only printing word instead of line in the list

Coding:

from fuzzywuzzy import fuzz
c = ['I am python', 'python is good', 'Everyone are humans']
print(max(c, key=lambda a: fuzz.ratio(a, 'good')))

Expected Output:

python is good

I get a single word instead of line of highest fuzzyvalue from the list. Please help to fix my code! Answers will be appreciated!

jww
  • 97,681
  • 90
  • 411
  • 885
asey raam
  • 23
  • 1
  • 3

2 Answers2

1

Your code seems ok, most likely your c array is initialized incorrectly and contains words instead of sentences. You code should be similar to this:

from fuzzywuzzy import fuzz

c = ['I am python', 'python is good', 'Everyone are humans']
print(max(c, key=lambda a: fuzz.ratio(a, 'good')))
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
0
from fuzzywuzzy import fuzz

c = ['I am python', 'python is good', 'Everyone are humans']
l = [(i,fuzz.ratio(i,'good')) for i in c]
l.sort(key=lambda a: a[1], reverse=True)
Farhadix
  • 1,395
  • 2
  • 12
  • 25
  • 1
    This answer may solve the problem but please consider expanding it so that it is useful for future visitors as well. You can explain what was wrong with the OP's code and what you did to fix it. – kylieCatt Aug 16 '14 at 18:59