[Tutor] Finding the differences between two lists
John
washakie at gmail.com
Thu Aug 25 20:59:53 CEST 2011
Not entirely sure, but I think it is as simple as:
scanResults = open('scanResults.txt', 'r').readlines()
verifiedList = open('verifiedList.txt', 'r').readlines()
Now both are lists. I assume each mac address is on it's own line?
-john
On Thu, Aug 25, 2011 at 8:56 PM, Justin Wendl <justin.wendl at gmail.com> wrote:
> 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
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Configuration
``````````````````````````
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Python 2.6
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
Basemap: 1.0
Matplotlib: 1.0.0
More information about the Tutor
mailing list