python中str.find和 in list的区别使用

在一复个str中查找特定的制字符串,使用string1.find(substring)的语法,这种查找时一种模糊查找;
但是在一个list中,如果判断是否包含某个项目,是一个绝对的相等的比较,空格都需要匹配;

所以使用查找匹配时可以采用的方法是:
1.将list转化为str之后模糊匹配:

比如 if str(list1).find(substring) != -1

2.将list中的所有的字符串都去掉特殊字符以及空格;
比如:
for item in list1:
item.replace(' ','')
再用if substring in list1:

② python 模糊查询

字符串有个function叫startswith

根据你的内容我提供一段代码

for str in list:
if str.startswith('a'):
print "found it!",str

楼主测试下哈,我用的是2.x。专

有问题再联系我~属~蟒蛇小组祝您编程愉快!

③ 如何使用python在hbase里进行模糊查询

注意:正则的写法可能不对,保证能过滤出数据,但是可能不会严格匹配,正则问题请自己解决;
#导入thrift和habse包
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
#此处可以修改地址和端口
host = '192.168.1.1'
#默认端口为9090
port = 9090
#要查询的表名
table = 'table_name'
#定义一个过滤器,此为关键步骤
filter = "RowFilter(=,'regexstring:.3333.')" #此行原创:)
# Make socket
transport = TSocket.TSocket(host, port)
# Buffering is critical. Raw sockets are very slow
# 还可以用TFramedTransport,也是高效传输方式
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
#传输协议和传输过程是分离的,可以支持多协议
protocol = TBinaryProtocol.TBinaryProtocol(transport)
#客户端代表一个用户
client = Hbase.Client(protocol)
#打开连接
try:
transport.open()
scan.filterString=filter
scanner = client.scannerOpenWithScan(table, scan)
except Exception:
finally:
client.scannerClose(scan)
transport.close()

④ python字典,如何查找值中包含指定字符串的键

1、说明python中检测字典的键中是否含有某串字符,便利字典键值,再判断字符串是否在键值中即可。2、示例代码:# 定义一个字典dic = {'1984/1/2': 123, '1984/1/3': 0, '1985/1/1': 156}# 遍历字典键中是否包含1984for key in dic: if '1984' in key: print('键值中包含字符串"1984"') # 或者需要的其它操作 else: print('键值中不包含字符串"1984"')3、执行结果:键值中包含字符串"1984"键值中不包含字符串"1984"键值中包含字符串"1984"

4、其它说明:python使用for in直接操作字典就是遍历字典的键值,python使用in操作来判断字符串中是否包含子串最方便,要优于使用字符串的函数index或者find。

index函数在找不到子串时会报错,find函数会返回-1。

⑤ 请教python匹配中文字符的方法

#-*-coding:UTF-8-*-
__author__=u'丽江海月客栈'

s="""{"hearl":"","nickname":"","loginstatus":"","loginstate":"","tip":"未注册服务","idUser":"","sessionId":"","upgradeUrl":"","checkCodeKey":"false"}"""

ss=s.decode('utf-8')

importre


re_words=re.compile(u"[u4e00-u9fa5]+")
m=re_words.search(ss,0)
printm.group()

⑥ 如何使用python在hbase里进行模糊查询

for key, data in graph_table.scan(filter="SingleColumnValueFilter('cf', 'id', <, 'binary:%s', true, false)" % struct.pack(">q", 1000)):
print key, data

这个语句是查询id<1000的,你改一下吧。。。。真心内没用容过HBase

⑦ python sqlite3 如何模糊查询变量

刚刚研究了一下,我的代码是在python 3.2.3下的。不知你的版本是多少,姑且参考吧。 以下代码根据python的手册里的例子改编。import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.execute("create table people (name, age)") who = "Yeltsin"age = 72# This is the qmark style: cur.execute("insert into people values (?, ?)", (who, age)) # Query using like clause cur.execute("select * from people where name like ?",('%Yel%',))。

⑧ python中模糊查询文件,并把查询内容标为红色

模糊查询用正则应该就可以做到
你所谓的标为红色就不知道是什么意思了

⑨ python 简单模糊匹配

for find in xx:
这个xx是那里冒出来的
是不是
for find in rowValuelist:

⑩ 我在学习python编程,请问下怎么实现模糊查询

importre
f=open('user.txt','r')
text=f.read()
f.close()
tofind=raw_input("pleaseinputyowanttofind:")
tofind=re.escape(tofind)
result=re.findall(".*"+tofind+".*",text)
forlineinresult:printline