Python: Searching for common values in two files
<p>I have two files that I loaded into Python, and I am trying to output a list that will display the common values between the two.</p>

<p>The list from the first file looks like this (not full list, just part of it):</p>

<pre><code>    [datetime.datetime(2010, 7, 30, 12, 20, 19, 143000), datetime.datetime(2010, 7, 30, 12, 22, 33, 631000), datetime.datetime(2010, 7, 30, 12, 22, 41, 236000), datetime.datetime(2010, 7, 30, 12, 23, 43, 547000), datetime.datetime(2010, 7, 30, 12, 23, 57, 453000), datetime.datetime(2010, 7, 30, 12, 26, 4, 713000), datetime.datetime(2010, 7, 30, 12, 26, 9, 46000), datetime.datetime(2010, 7, 30, 12, 28, 30, 313000)]
</code></pre>

<p>And the second list looks like this (again, not the full list, just part of it):</p>

<pre><code>    [datetime.datetime(2010, 7, 30, 13, 43, 2, 993000), datetime.datetime(2010, 7, 30, 13, 43, 10, 917000), datetime.datetime(2010, 7, 30, 13, 48, 56, 697000), datetime.datetime(2010, 7, 30, 13, 49, 14, 399000), datetime.datetime(2010, 7, 30, 13, 51, 45, 882000), datetime.datetime(2010, 7, 30, 13, 52, 6, 432000), datetime.datetime(2010, 7, 30, 13, 54, 26, 873000), datetime.datetime(2010, 7, 30, 13, 59, 2, 164000), datetime.datetime(2010, 7, 30, 13, 59, 15, 515000), datetime.datetime(2010, 7, 30, 14, 3, 43, 742000), datetime.datetime(2010, 7, 30, 14, 5, 59, 975000), datetime.datetime(2010, 7, 30, 14, 13, 36, 887000), datetime.datetime(2010, 7, 30, 14, 13, 42, 92000)]
</code></pre>

<p>And here is what the code looks like:</p>

<pre><code>    for infilelines in text:
        lspl1 = infilelines.split(',')
        cattime = lspl1[2]
        catdate.append(datetime.strptime(lspl1[1]+cattime,'%d/%m/%Y%H:%M:%S.%f'))



    #print catdate


    NNSRCfile = sf.readsrc(NNSRC)
    l1 = NNSRCfile['date']
    l2 = NNSRCfile['time']
    NNSRCfile['datetime2'] = zip(l1,l2)
    #print NNSRCfile['datetime2']


    NNSRCfile['datetimenew'] = [datetime.strptime(i+j,'%m-%d-%Y%H:%M:%S.%f') for i,j in zip(l1,l2)]

    #print NNSRCfile['datetimenew']
    ii = 0
    while ii &lt;= len(catdate):
        try:
            #print NNSRCfile['datetimenew'].index(catdate[ii]), "WE FOUND A MATCH!!!!"
            indices = NNSRCfile['datetimenew'].index(catdate[ii])
        except:
            print "No match."
            #continue
        ii += 1
</code></pre>

<p>I am not getting an error, but the script is not working the way I intended it to. I would like a full list of all of the common elements between the two separate lists. I know I didn't include the full lists in this post, but when I manually look through it, I know there are commonalities between the two.</p>

<p>Any help is greatly appreciated!</p>
