【发布时间】:2017-05-17 01:07:53
【问题描述】:
我有两个制表符分隔 (tsv) 文件。我想在 tsv 文件中获得与两个文件的特定列的项目匹配的输出。我是python新手,如果我能得到一些cmets会很棒。
输入文件1:
#comment one
#comment two and more
ab123 1 339 GT + s4
ab222 3 23 CT - se4
ab1100 3 523 AA + aa11
ab2211 20 166 TT + ss
输入文件2:
ab123 1
ab1100 3
通过匹配 file2 的第一列,预期输出是输入 file1 的前 4 列:
ab123 1 339 GT
ab1100 3 523 AA
我正在尝试的代码是:
with open("file1") as data:
for line1 in data:
with open("file2") as id:
for line2 in id:
if str(line2) in line1:
print line1
【问题讨论】: