Home > other >  Matching questions: array fuzzy classification
Matching questions: array fuzzy classification

Time:04-10

Begin with the lake in fuzzy query array element

A=[hunan, hubei, lake, reservoir, lake and comfortable, henan, hebei, shandong, shanxi]
Case 1:
Difflib. Get_close_matches (' lake ', a)
[hunan, hubei, lake reservoir]

Case 2:
Difflib. Get_close_matches (' lake ', a, 4)
Hunan, hubei, lake reservoir, lake comfortable]

Case 3:
Difflib. Get_close_matches (' lake ', a, 1)

[hunan, hubei, lake, reservoir, lake and comfortable, henan, hebei, shandong, shanxi]

This method can realize classification, but the results show there is a problem
Case 1: default return only three value, the value of the
no return
Case 2: add return parameter can specify the number of the return value, but not convenient, in the field can't statistics

Case 3: direct return all, did not have the effect of filtering

Ask bosses good solution,



CodePudding user response:

 a=[' of hunan, hubei, 'lake reservoir, lake' comfortable ', 'henan', 'hebei, shandong,' the shanxi '] 
E=filter (lambda x: x [0]=='lake', a)
Print (list (e))
  • Related