我的目标是尝试将字符串列表与整数列表进行匹配:
例如我的字符串列表:wholelookup[uniprotID] = [A177T,I126T,M418T]
。
我的整体列表:lookup[uniprotID] = [177,126,418]
。
如果有匹配,那么我想在wholelookup中打印令牌。
这是我到目前为止的结果,但结果并没有打印出任何内容:
for item in lookup[uniprotID]:
for names in wholelookup[uniprotID]:
if start <= item <= end and re.match(item, names) :
item, start, end = map(int, (item, start, end))
print names
答案 0 :(得分:0)
match
尝试从头开始匹配。另外:您不希望将1
与a321a
匹配。
您可以使用're.match(r'\ w'+ str(item)+ r'\ w',名称)'而不是re.match(item, names)
或使用re.search
:
re.search(r'\d+',names).group(0)==item
答案 1 :(得分:0)
为什么要使用正则表达式?
假设start
和end
已经是整数,而item
是一个字符串,请尝试以下方法:
for item in lookup[uniprotID]:
if start <= int(item) <= end: continue
for names in wholelookup[uniprotID]:
if str(item) in names :
print names