python 模糊匹配
2017-09-25 16:21
253 查看
import re def fuzzyfinder(input, collection, accessor=lambda x: x): """ Args: input (str): A partial string which is typically entered by a user. collection (iterable): A collection of strings which will be filtered based on the `input`. Returns: suggestions (generator): A generator object that produces a list of suggestions narrowed down from `collection` using the `input`. """ suggestions = [] input = str(input) if not isinstance(input, str) else input pat = '.*?'.join(map(re.escape, input)) regex = re.compile(pat) for item in collection: r = regex.search(accessor(item)) if r: suggestions.append((len(r.group()), r.start(), accessor(item), item)) return (z[-1] for z in sorted(suggestions))
相关文章推荐
- Python 模糊匹配:glob, re, fnmatch
- python使用rabbitmq实例五,路由键模糊匹配(5)
- python使用rabbitmq实例五,路由键模糊匹配
- 利用编辑距离的子串模糊匹配——python实现
- python 之实现模糊匹配
- python 在MySQL中的模糊匹配
- python使用rabbitmq实例五,路由键模糊匹配
- Python下用List对员工信息表进行模糊匹配
- hbase时间段查询、模糊匹配
- Python cookbook(字符串与文本)在字符串的开头或结尾处进行文本匹配操作
- mysql like模糊匹配是按照匹配度排序
- Python匹配利器-正则表达式(附赠爬图小程序)
- 基于ORB特征提取算法图像匹配 python实现
- 转:zTree树控件扩展篇:巧用zTree控件实现文本框输入关键词自动模糊查找zTree树节点实现模糊匹配下拉选择效果
- Yaf-Mongo 模糊匹配字符串并删除
- FIRST_ROWS优化模式语言排序模糊匹配问题
- Python-同时匹配邮箱和电话号码的正则表达式
- Opencv2.4 Python SURF 匹配
- SQL中模糊查询的模式匹配
- python 3.x 分析日志的模块(正则匹配)