網站首頁 編程語言 正文
Python字符串模糊匹配
Python的difflib庫中get_close_matches方法
包含四個參數
-
x
:被匹配的字符串。 -
words
:去匹配的字符串列表。 -
n
,前topn個最佳匹配返回,默認為3。 -
cutoff
:匹配度大小,為[0, 1]浮點數,默認數值0.6。
import difflib list1 = ['ape', 'apple', 'peach', 'puppy'] difflib.get_close_matches('appel', list1)
import keyword difflib.get_close_matches('wheel', keyword.kwlist)
difflib.get_close_matches('pineapple', keyword.kwlist)
difflib.get_close_matches('accept', keyword.kwlist)
利用這個功能就能夠實現SQL中的LIKE模糊查詢。?
python-re模塊,模糊匹配
import re def fuzzyMatch(): value = '西西' list = ['大海西西的', '大家西西', '打架', '西都好快', '西西大化'] pattern = '.*' + value + '.*' for s in list: obj = re.findall(pattern, s) if len(obj) > 0: a = s print(a) break fuzzyMatch()
原文鏈接:https://blog.csdn.net/Jeremiah_/article/details/121806739
相關推薦
- 2022-12-10 Flutter改變狀態變量是否必須寫在setState回調詳解_Android
- 2022-10-19 react-redux集中式狀態管理及基本使用與優化_React
- 2022-03-22 C語言寫一個散列表_C 語言
- 2022-02-26 微信小程序 - 將頁面可分享到朋友圈功能(兩步完成)
- 2022-04-25 ASP.NET?Core?Web資源打包與壓縮技術介紹_實用技巧
- 2022-12-14 Flutter應用框架搭建實現屏幕適配方案詳解_Android
- 2022-09-05 C語言中如何實現單鏈表刪除指定結點_C 語言
- 2022-08-04 Python中reduce函數詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支