<div dir="ltr">The iterator is not revaluated, instead, it is constructing a single iterator, in this case a list_iterator. The list_iterator looks at the underyling list to know how to iterate so when you mutate the underlying list, the list_iterator sees that. This does not mee the expression used to generate the iterator was re-evaluated.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 11:25 AM, John Doe <span dir="ltr"><<a href="mailto:z2911@bk.ru" target="_blank">z2911@bk.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To pass by reference or by copy of - that is the question from hamlet. ("hamlet" - a community of people smaller than a village python3.4-linux64)<br>
<br>
xlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br>
i = 0<br>
for x in xlist:<br>
print(xlist)<br>
print("\txlist[%d] = %d" % (i, x))<br>
if x%2 == 0 :<br>
xlist.remove(x)<br>
print(xlist, "\n\n")<br>
i = i + 1<br>
<br>
So, catch the output and help me, PLEASE, improve the answer:<br>
Does it appropriate ALWAYS REevaluate the terms of the expression list in FOR-scope on each iteration?<br>
But if I want to pass ONCE a copy to FOR instead of a reference (as seen from an output) and reduce unreasonable reevaluation, what I must to do for that?<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/joe%40quantopian.com" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/joe%40quantopian.com</a><br>
</blockquote></div><br></div>