擅长:python、mysql、java
<p>第一个with语句是读取id文件并创建包含条目的字典。最后一个with将从另一个文件中读取条目,并将正确的条目放入字典中</p>
<pre><code>import re
regex = re.compile('[A-Z0-9]+:\d+:[A-Z0-9]+:\d+:\d+:\d+:\d+')
with open('id.bam') as file:
ids = {}
for line in file:
if regex.match(line):
temp = line.replace('\n', '')
ids[temp] = []
print(ids)
with open('list.bam') as file:
for line in file:
if regex.match(line):
temp = line.replace('\n', '').split(' ')
if temp[0] in ids:
ids[temp[0]].append(line.replace('\n', ''))
print(ids)
</code></pre>