python 之实现模糊匹配

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env pythong
#_*_ coding:utf-8 _*_
import  re
#
data  =  [
'tantianran phone 118' ,
'tanyongxing phone 110' ,
'tansufen phone 119' ,
'dengwenyi phone 118' ,
'dengwenqing phone 520' ,
'laowang phone 110' ,
'zhongjianwei 112'
]
 
def  findes(user_input,data):
sugge  =  []
pat  =  '.*' .join(user_input)
regex  =  re. compile (pat)
for  item  in  data:
match  =  regex.search(item)
if  match:
sugge.append(item)
return  sugge
 
strs  =  raw_input ( '输入查找的字符:' )
print  '查找结果'
for  in  findes(strs,data):
print  "\033[31m %s \033[0m"  %  i



本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/1869828
相关文章
Python print() 打印两个 list ,实现中间换行
Python print() 打印两个 list ,实现中间换行
|
Python
Python实现因子分析(附案例实战)
Python实现因子分析(附案例实战)
1038 0
Python实现因子分析(附案例实战)
|
JSON 区块链 数据格式
Python实现一个简单的区块链
本文介绍如何用Python实现一个简单的区块链。
482 0
|
存储 数据安全/隐私保护 计算机视觉
python 实现pacs功能 推送下拉影像
python 实现dcmtk关联pacs功能 推送下拉影像
229 0
python 实现pacs功能 推送下拉影像
|
算法 大数据 Python
Leedcode 每日一练 搜索二维矩阵Ⅰ Python实现
Leedcode 每日一练 搜索二维矩阵Ⅰ Python实现
122 2
Leedcode 每日一练 搜索二维矩阵Ⅰ Python实现
|
前端开发 Python
Leecode加法题目3个 每日练习 Python实现
Leecode加法题目3个 每日练习 Python实现
87 0
Leecode加法题目3个 每日练习 Python实现
|
iOS开发 Python
Python实现微信消息连续发送
Python实现微信消息连续发送
Python实现微信消息连续发送
python实现微信小游戏“飞机大战”
python实现微信小游戏“飞机大战”
python实现微信小游戏“飞机大战”
|
Python
Python分分钟实现图书管理系统(含代码)
Python分分钟实现图书管理系统(含代码)
286 0
|
JSON 算法 数据安全/隐私保护
Python:使用PyJWT实现JSON Web Tokens加密解密
Python:使用PyJWT实现JSON Web Tokens加密解密
244 0

热门文章

最新文章