I did a script to compare two files, count the elements and say how much times they appear. This information is saved in a new file. This last file, unfortunately, contains numbers and words. I need only the rows that starts with words in general (strings).
The initial code is this:
f1 = open("file1.txt", 'r')
f2 = open("file2.txt", 'r')
words1 = f1.read().split()
words2 = f2.read().split()
words = set(words1) & set(words2)
with open('outfile.txt', 'w') as output:
for word in words:
output.write('{} appears {} times in f1 and {} times in f2.\n'.format(word, words1.count(word), words2.count(word)))
The file out is made by this kind of text and I need only when starts with a word, e.g. ACTION
for this lines:
ACTION appears 1 times in f1 and 1 times in f2.
1150.00 appears 3 times in f1 and 1 times in f2.
1.18233875e-05 appears 1 times in f1 and 1 times in f2.
2.52229049e-09-1.85248240e-13 appears 1 times in f1 and 1 times in f2.
8.85017800e-09-1.22652064e-12-1.37945792e+04 appears 1 times in f1 and 1 times in f2.