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
i
in
findes(strs,data):
print
"\033[31m %s \033[0m"
%
i
|
本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/1869828