我想用一个查询文件.txt作为源文件,用于搜索每一行并将其与数据文件.txt. 但是数据文件.txt有不同的结构。你知道吗
你知道吗查询文件.txt应该是这样的:
Gina Cooper
Asthon Smith
Kim Lee
而数据文件.txt看起来像这样:
Gina Cooper
112 Blahblah St., NY
Leigh Walsh
09D blablah, Blah
Asthon Smith
another address here
Kim Lee
another address here
我要把名字和后面的线都记下来。下面是在两个文件中获取匹配名称的代码,这是dstromberg(https://stackoverflow.com/a/19934477)的修改代码:
with open('querfile.txt', 'r') as input_file:
input_addresses = set(names.rstrip() for names in input_file)
with open('datafile.txt', 'r') as data_file:
data_addresses = set(names.rstrip() for names in data_file)
with open('names_address.txt', 'w') as output:
names_address=("\n".join(input_addresses.intersection(data_addresses)))
output.write(names_address)
总之,我想在我的outfile(name)中看到什么_地址.txt)是名字加上他们名字对应的地址,基本上是下一行。我一个月前刚开始玩Python,我相信我是卡住了。谢谢谢谢你的帮助。你知道吗
重写以下内容:
对此:
循环浏览选项,然后就可以抓取下一个索引:
这可能没有太大的时间复杂度,但您的数据集似乎
相关问题 更多 >
编程相关推荐