The order of iterable de-referencing in assignment?
Marko Rauhamaa
marko at pacujo.net
Wed Aug 24 07:09:56 EDT 2016
Shiyao Ma <i at introo.me>:
> Given a = [1, 2]
>
> a.extend(a) makes a = [1,2, 1,2]
>
> 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.
Functionally, Python's lists are not linked lists but, rather, vectors.
> My question is, is there any doc on the behavior of things like this?
No. It should be here:
<URL: https://docs.python.org/3/reference/datamodel.html>
It only states:
The items of a list are arbitrary Python objects.
and inexplicably muddies the waters by continuing:
Lists are formed by placing a comma-separated list of expressions in
square brackets. (Note that there are no special cases needed to form
lists of length 0 or 1.)
(which has nothing whatsoever to do with the data model).
Marko
More information about the Python-list
mailing list