I am looking for some better way to parse a huge file. Following is the example of the file.
sample.txt
'abcdefghi'
'xyzwfg'
'lmnop'
Out of which I am looking for 'abc' and 'xyz' in the file at least once
I was able to find them but I am looking for some better way. Following is my code
datafile = file('sample.txt')
abc = 0
xyz = 0
found - True
for line in datafile:
if 'abc' in line:
abc += 1
break
for line in datafile:
if 'xyz' in line:
xyz += 1
break
if (abc + xyz) >= 2:
print 'found'
else:
print 'fail'
I am running a loop twice. So is there a better way to parse the file?
breaksuggests no.