Comparing two generators in Python
<p>I am wondering about the use of <code>==</code> when comparing two generators</p>

<p>For example:</p>

<pre><code>x = ['1','2','3','4','5']

gen_1 = (int(ele) for ele in x)
gen_2 = (int(ele) for ele in x)
</code></pre>

<p><strong>gen_1</strong> and <strong>gen_2</strong> are the same for all practical purposes, and yet when I compare them:</p>

<pre><code>&gt;&gt;&gt; gen_1 == gen_2
False
</code></pre>

<p>My guess here is that <code>==</code> here is treated like <code>is</code> normally is, and since <strong>gen_1</strong> and <strong>gen_2</strong> are located in different places in memory:</p>

<pre><code>&gt;&gt;&gt; gen_1
&lt;generator object &lt;genexpr&gt; at 0x01E8BAA8&gt;
&gt;&gt;&gt; gen_2
&lt;generator object &lt;genexpr&gt; at 0x01EEE4B8&gt;
</code></pre>

<p>their comparison evaluates to <code>False</code>. Am I right on this guess? And any other insight is welcome.</p>

<p>And btw, I do know how to compare two generators:</p>

<pre><code>&gt;&gt;&gt; all(a == b for a,b in zip(gen_1, gen_2))
True
</code></pre>

<p>or even</p>

<pre><code>&gt;&gt;&gt; list(gen_1) == list(gen_2)
True
</code></pre>

<p>But if there is a better way, I'd love to know.</p>
