I am attempting to create a small iterative string match function in Python. I am getting stumped as the first set of matching strings is caught, but the second set of matching strings is not. I added a string conversion to ensure the objects were strings. It is also my understanding that the == operator matches values, not objects. (Correct me if my terminology is wrong). Any help would be appreciated.
#!/usr/bin/python
import re
NameLG_file = open("Name2.txt", "r")
NameSM_file = open("Inc2.txt", "r")
SMList = []
LGList = []
# Assign LG to List and Format
for a in NameLG_file:
a = a.strip('\n')
a = a.replace('\"', '')
a = str(a)
LGList.extend([a])
# Assign SM to list and format
for c in NameSM_file:
c = c.strip('\n')
c = str(c)
SMList.extend([c])
# Identify and list orphans.
for e in LGList:
for f in SMList:
if e == f:
print True
print e
print f
print ""
# break
else:
print False
print e
print f
print ""
NameLG_file.close()
NameSM_file.close()
Name2.txt contains
"teardown"
"Elite"
Binary
Inc2.txt contains
teardown
Elite
The output is:
True
teardown
teardown
False
teardown
Elite
False
Elite
teardown
False
Elite
Elite
False
Binary
teardown
False
Binary
Elite
As such I want the matching Elite strings to show True. Thanks in advance!