擅长:python、mysql、java
<p>可以使用<a href="https://docs.python.org/2/library/sets.html" rel="nofollow">Set</a>进行模式匹配:</p>
<pre><code>from sets import Set
full_log = ['AB21','BG54','HG89','NS72','Error','CF54','SD62','KK02','FE34']
tc1 = ['HG89','NS72']
tc2 = ['AB21','BG54']
tc3 = ['KK02','FE34']
tc4 = ['CF54','SD62']
set(full_log) & set(tc1)
</code></pre>
<p>输出:<code>{'HG89', 'NS72'}</code></p>
<pre><code>#Finding index of set elements:
result=set(full_log) & set(tc1)
def all_indices(value, qlist):
indices = []
idx = -1
while True:
try:
idx = qlist.index(value, idx+1)
indices.append(idx)
except ValueError:
break
return indices
r=[]
for i in range(len(result)):
s=all_indices(list(result)[i], full_log)
r.append(s)
r
Output: [[2], [3]]
</code></pre>