i'm looking for some help with my code, it's a simple python code, but i'm new at this so it's been a little tricky for me..
What i want to do is just to take a .txt file, read it and compare it to some strings and say which words of the .txt file don't have the strings I'm asking, for example:
txt file: ABCD AABC DDCA CDAA CDAB EEGF GFFE
And my string restricctions: S= ['AA', 'BB', 'CC', DD']
so in the output should go something like: ABCD CDAB EEGF GFFE
the other ones can't be shown because they match with one or more of the strings in S. Now, my code and my problem.
I have the following code:
import string
ins = open( "prueba.txt", "r" )
array = []
for line in ins:
array.append( line )
ins.close()
s = ''.join(array)
a= s.split()
c = ['AA', 'BB','CC', 'DD','EE', 'FF','GG', 'HH','II', 'JJ','KK', 'LL', 'MM', 'NN','OO', 'PP','QQ', 'RR','SS', 'TT','UU', 'VV', 'WW', 'XX','YY', 'ZZ']
i=0
j=0
f= c[j]
for j in range(0,len(a)):
if a[i].find(f) != -1:
print 'Is in:' , a[i]
i=i+1
else:
print 'Is not in:' , a[i]
i=i+1
And the following txt file: AAC ABC ACC ADD FAA
The output i'm having is: Is in: AAC Is not in: ABC Is not in: ACC Is not in: ADD Is in: FAA
What I can see from this, is that my code isn't iterating how it should, so it's not printing the right answer.
I've been trying a lot of things to fix it, but I just can't get to the solution, so if anyone can help me with this I'll really appreciate it!
Thanks a lot!