擅长:python、mysql、java
<pre><code>#Create a set of all the records from the first file
lookup = set(open("test01.txt").read().splitlines())
#and then open the second file for reading and a new out file
#for writing
with open("test02.txt") as fin, open("test02.out","w") as fout:
#iterate through each line in the file
for line in fin:
#and split it with the seperator
line = map(str.strip, line.split(":"))
#if the key is in the lookup set
if line[0] in lookup:
#replace it with space
line[0] = " "
#and then join the line tuple and suffix with newline
line = ":".join(line) + "\n"
#finally write the resultant line to the out file
fout.write(line)
</code></pre>