]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #23406: Clarify documentation on multiplying a sequence
authorMartin Panter <vadmium>
Mon, 7 Sep 2015 01:40:33 +0000 (01:40 +0000)
committerMartin Panter <vadmium>
Mon, 7 Sep 2015 01:40:33 +0000 (01:40 +0000)
Patch from Matheus Vieira Portela.

Doc/faq/programming.rst
Doc/library/stdtypes.rst
Misc/ACKS

index 23891be14f90cd378848f14ae546e2224468e977..135ae521fbd101310f4872caa7a0dd9d8dbc8198 100644 (file)
@@ -1280,6 +1280,8 @@ analogue of lisp car is ``lisp_list[0]`` and the analogue of cdr is
 usually a lot slower than using Python lists.
 
 
+.. _faq-multidimensional-list:
+
 How do I create a multidimensional list?
 ----------------------------------------
 
index bb918df3d4fc0543a85f44f335a87c582a142b98..86aae512c4f2c588c8c0b53b2192b4570573ce6b 100644 (file)
@@ -736,8 +736,8 @@ In the table, *s* and *t* are sequences of the same type; *n*, *i* and *j* are i
 | ``s + t``        | the concatenation of *s* and   | \(6)     |
 |                  | *t*                            |          |
 +------------------+--------------------------------+----------+
-| ``s * n, n * s`` | *n* shallow copies of *s*      | \(2)     |
-|                  | concatenated                   |          |
+| ``s * n, n * s`` | equivalent to adding *s* to    | \(2)     |
+|                  | itself *n* times               |          |
 +------------------+--------------------------------+----------+
 | ``s[i]``         | *i*\ th item of *s*, origin 0  | \(3)     |
 +------------------+--------------------------------+----------+
@@ -789,9 +789,9 @@ Notes:
 
 (2)
    Values of *n* less than ``0`` are treated as ``0`` (which yields an empty
-   sequence of the same type as *s*).  Note also that the copies are shallow;
-   nested structures are not copied.  This often haunts new Python programmers;
-   consider:
+   sequence of the same type as *s*).  Note that items in the sequence *s*
+   are not copied; they are referenced multiple times.  This often haunts
+   new Python programmers; consider:
 
       >>> lists = [[]] * 3
       >>> lists
@@ -801,7 +801,7 @@ Notes:
       [[3], [3], [3]]
 
    What has happened is that ``[[]]`` is a one-element list containing an empty
-   list, so all three elements of ``[[]] * 3`` are (pointers to) this single empty
+   list, so all three elements of ``[[]] * 3`` are references to this single empty
    list.  Modifying any of the elements of ``lists`` modifies this single list.
    You can create a list of different lists this way:
 
@@ -812,6 +812,9 @@ Notes:
       >>> lists
       [[3], [5], [7]]
 
+   Further explanation is available in the FAQ entry
+   :ref:`faq-multidimensional-list`.
+
 (3)
    If *i* or *j* is negative, the index is relative to the end of the string:
    ``len(s) + i`` or ``len(s) + j`` is substituted.  But note that ``-0`` is still
index 59d0914c1f40f5a6a22337b212a5b483db655338..5650f9b053f88ef6b5dfecef0f51c6f57f10320e 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1084,6 +1084,7 @@ Martin Pool
 Iustin Pop
 Claudiu Popa
 John Popplewell
+Matheus Vieira Portela
 Davin Potts
 Guillaume Pratte
 Florian Preinstorfer