The order of iterable de-referencing in assignment?

Joaquin Alzola Joaquin.Alzola at lebara.com
Wed Aug 24 07:03:52 EDT 2016


>> One might guess a.extend(a) would turn into an infinite loop.  It turns out here Python first gets all the items of `a' and then append them to `a', so the infinite loop is avoided.
>>> a = [1,2]
>>> for x in a: a.append(x)
>...
>^CTraceback (most recent call last):
 > File "<stdin>", line 1, in <module>
>KeyboardInterrupt
>>>> len(a)
>6370805

>That right there, folks, is an infinite loop.

If I am correct python points out an infinite loop with the "...", just pointing to more information.
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.



More information about the Python-list mailing list