Answer the question
In order to leave comments, you need to log in
Working with strings. Algorithm?
Guys. Hello.
You need to write a script. Which will delete words from one text file "A" that are found in another text file "B".
I don’t really understand how to make this algorithm and what, let’s say, functions should be used?
But the most important thing is the algorithm!
Answer the question
In order to leave comments, you need to log in
The solution is to load both files into separate arrays and check element by element A for the presence of an element in B. According to the results of the check, delete / skip. Rewrite the resulting array to file A.
Recently, there seemed to be a similar question =) you also asked for a script. Yes?
file 1 (a=222, b=333, c=444, d=333), file 2 (222 333)
Result (c=444, d=333)
Super shitty code, but you get the point, I hope.
l = list()
with open('2.txt') as f:
for line in f.readlines():
l.append(line.replace('\n',''))
res = list()
with open('1.txt') as f2:
for line in f2.readlines():
res.append(line.replace('\n',''))
res = filter(lambda x: x.split('=')[-1] not in l, res)
with open('12.txt', 'w') as f2:
for line in res:
f2.write(line+"\n")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question