Why does "del x" not change the result of the generator, but x.append does?
I can do it:
>>> x = [2,3,4]
>>> y = (v * 2 for v in x)
>>> del x # x is deleted
>>> print(list(y)) # y still exists
[4, 6, 8]
This may allow me to think that the generator y is independent of the list x. But I can also do this:
>>> a = [2, 3, 4]
>>> b = (v * 2 for v in a)
>>> a.append(5) # change a
>>> print(list(b)) # b is also changed
[4, 6, 8, 10]
This makes me feel like generator b is still pointing to list a. Therefore, I wonder how the generator is created. Or maybe there is something about how x is removed in the first case.