[Tutor] Finding the differences between two lists
Justin Wendl
justin.wendl at gmail.com
Thu Aug 25 20:56:02 CEST 2011
Hello,
Bare with me, as I am new to Python and a beginner programmer.
I am trying to compare two lists (not of the same length), and create a new
list of items that are -not- found in both lists.
Scenario: I have a list of MAC addresses that are known and good, and am
comparing it to a list of MACs found in a scan. I want to weed out the
those which are unknown. I am using IDLE (Python 2.7) on Windows, and all
files are in the same directory.
Code:
scanResults = open('scanResults.txt', 'r')
verifiedList = open('verifiedList.txt', 'r')
badMacs = []
for mac in scanResults:
if mac not in verifiedList:
print mac
badMacs.append(mac)
else:
break
When I print 'badMacs', the results come up empty:
[]
Any help would be greatly appreciated!
Regards,
Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110825/153721fb/attachment.html>
More information about the Tutor
mailing list