I found code to find the similarities (or differences) of lists on this page: How can I compare two lists in python and return matches
>>> set(a).intersection(b)
set([5])
However, it's not working when I compare a list I made to a list made by reading a file like so:
myvalues = ['a1', '2b', '3c'] # same values found in values.txt, line by line
with open('values.txt', 'r') as f:
filevalues = f.readlines()
for line in filevalues:
line = line.strip()
matches = set(myvalues).intersection(filevalues)
print matches
output:
set([])
It DOES work on two slightly different lists I made in the script itself, and DOES work when I compare the filevalues to filevalues. Not sure what I'm missing but I'm guessing the problem has something to do with the types or format of the list that is created by reading the file's lines.
Anyone know how to go about troubleshooting this?