Deleting a list after creating an iterator object from it
<p>I am trying to understand the concept of iterators in python and tried this in Python 3.5.2.</p>

<pre><code>x = list(range(1000))    # size of x is 9112 bytes
y = iter(x)              # size of y is 56 bytes
del x
x = list(y)              # size of x is again 9112 bytes
</code></pre>

<p>How does the iterator store the information about the sequence it has to generate?</p>

<p>It does not contain all the elements but even after deleting the original list we are still able to reproduce the original list from the iterator?</p>

<p>If it does not contain all the elements how does it know which is the next element even after deleting <code>x</code>?</p>

<p>According to what I know, del x does not del the value in the memory since your y is still referring it. It is kind of pointer. x and y is referring to the same memory. </p>

<p>when you do del x, python will dereference the x and do garbage collection.</p>

<p>while by doing x=list(y), you are pointing the memory to x again.</p>

python iterator iterable