Best algorithm to compare list or dict
<p>I'm dealing with a bit complicated data set via Python. I'm a novice Python coder. The data set is the collection of Date, Title, Contents and URL.</p>

<p>Conceptually, it will be like this.</p>

<pre><code>1st scraping runs, then I get,

[9/6 9:00, title1, content1]
[9/6 9:00, title2, content2]
[9/6 8:22, title3, content3]
[9/6 11:01, title4, content4]
...

2nd scraping runs, then I get,

[9/6 13:05, title5, content5]
[9/6 12:13, title6, content6]
[9/6 9:00, title1, content1]
[9/6 14:21, title4, content4'] ---&gt; This is updated of content4
...
</code></pre>

<p>I could run scraping code.
What I want to do is to compare the output of 1st scraping run and 2nd. 
I expect to show only diff.</p>

<pre><code>[9/6 13:05, title5, content5]
[9/6 12:13, title6, content6]
[9/6 10:21, title4', content4']
</code></pre>

<p>I don't believe I have to compare "content". 
I can get the diff by "date" and "title" only.</p>

<p>I spent hours but cannot think of elegant approach to make this work..
What would be the best approach here? Basically, I'm thinking to store the output as pickle then compare the 2nd scrape run output on the fly. However, I'm not sure how to compare to get two elements of list simultaneously then compare with two elements from second list. It does not seem it is simple for loop...</p>

<p>Or, can this be done by dict?  I don't think so... but welcome to any suggestion.</p>

<p>It will be much appreciated if experienced folks could comment.</p>

<p>Try this for comparison between <code>list</code> in python 3:</p>

<pre><code>a= [['9/6 9:00', 'title1', 'content1'],
['9/6 9:00', 'title2', 'content2'],
['9/6 8:22', 'title3', 'content3'],
['9/6 11:01','title4', 'content4']]
b=[['9/6 13:05', 'title5', 'content5'],
['9/6 12:13', 'title6', 'content6'],
['9/6 9:00', 'title1', 'content1'],
['9/6 14:21', 'title4', 'content4']]
for i in b:
    if i not in a:
        print(i)
</code></pre>

<p>Output:</p>

<pre><code>['9/6 13:05', 'title5', 'content5']
['9/6 12:13', 'title6', 'content6']
['9/6 14:21', 'title4', 'content4']
</code></pre>

<p>Here it is directly comparing whole list to another list like  <code>['9/6 11:01','title4', 'content4']</code> to <code>['9/6 14:21', 'title4', 'content4']</code> so if any single element is different in <code>list</code> it shows that <code>list</code> but if you want to compare different element of <code>list</code> to another element in another <code>list</code> then you have to apply another method. </p>

<p><strong>Alternate Method</strong> (Which does the same but using <em>list comprehension</em>) :</p>

<pre><code>print(*[i for i in b if i not in a],sep='\n')
</code></pre>

<p>It will also gives same output:</p>

<pre><code>['9/6 13:05', 'title5', 'content5']
['9/6 12:13', 'title6', 'content6']
['9/6 14:21', 'title4', 'content4']
</code></pre>

<blockquote>
  <p>Here <em>list comprehension</em> part is only <code>[i for i in b if i not in a]</code>
  other <code>sep='\n'</code> is for displaying every element on next line. For
  understanding <em>list comprehension</em> see this document : <a href="http://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/" rel="nofollow">Python List
  Comprehensions: Explained Visually</a></p>
</blockquote>

<p>If you tell what difference we have to print then I can help because in question i don't understand the how we get <strong>9/6 10:21</strong> this output in line  <code>[9/6 10:21, title4', content4']</code></p>

python python-3.x compare