From ad9224fb83365ee6314fa16699f384a772b74708 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 15 Oct 2023 19:03:14 +0100 Subject: [PATCH 1/7] [Doc] Fixing sequence index range --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 75b656f385d34b..f4658c47995df5 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -296,7 +296,7 @@ Sequences single: item selection single: subscription -These represent finite ordered sets indexed by non-negative numbers. The +These represent finite ordered sets indexed by integer numbers. The built-in function :func:`len` returns the number of items of a sequence. When the length of a sequence is *n*, the index set contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. From 3d22a1e61fea797ade15bede4c505a8190171ba6 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 15 Oct 2023 19:12:21 +0100 Subject: [PATCH 2/7] [Doc] Add information about sequence indexes values --- Doc/reference/datamodel.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index f4658c47995df5..9c66e3e2c495e2 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -298,8 +298,13 @@ Sequences These represent finite ordered sets indexed by integer numbers. The built-in function :func:`len` returns the number of items of a sequence. When -the length of a sequence is *n*, the index set contains the numbers 0, 1, -..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. +the length of a sequence is *n*, the index set contains the numbers -*n*, +-*n*+1, -*n*+2, ..., 0, 1, ..., *n*-1. + +For non-negative numbers, the item *i* of sequence *a* is selected by ``a[i]``. + +For negative numbers, -1 is the last item and -2 is the penultimate (next to +last) item and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. .. index:: single: slicing From 81ce055b55c9c9625dee645a1af2debe9ffc57bc Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 25 Mar 2024 14:56:27 +0000 Subject: [PATCH 3/7] [Doc] Adding reference to subscription and slicing operations on sequence type definition --- Doc/reference/datamodel.rst | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 9c66e3e2c495e2..1b6c191678ad6c 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -296,26 +296,14 @@ Sequences single: item selection single: subscription -These represent finite ordered sets indexed by integer numbers. The +These represent finite ordered sets indexed by non-negative numbers. The built-in function :func:`len` returns the number of items of a sequence. When -the length of a sequence is *n*, the index set contains the numbers -*n*, --*n*+1, -*n*+2, ..., 0, 1, ..., *n*-1. +the length of a sequence is *n*, the index set contains the numbers 0, +1, 2, ..., *n*-1. -For non-negative numbers, the item *i* of sequence *a* is selected by ``a[i]``. - -For negative numbers, -1 is the last item and -2 is the penultimate (next to -last) item and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. - -.. index:: single: slicing - -Sequences also support slicing: ``a[i:j]`` selects all items with index *k* such -that *i* ``<=`` *k* ``<`` *j*. When used as an expression, a slice is a -sequence of the same type. This implies that the index set is renumbered so -that it starts at 0. - -Some sequences also support "extended slicing" with a third "step" parameter: -``a[i:j:k]`` selects all items of *a* with index *x* where ``x = i + n*k``, *n* -``>=`` ``0`` and *i* ``<=`` *x* ``<`` *j*. +Sequences are instances of a :ref:`container class `, so they +support the :ref:`subscription ` and :ref:`slicing ` +operations. Sequences are distinguished according to their mutability: From 2441a7dcfeb9871c9a3edc9762002f42ca62ae4c Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 25 Mar 2024 19:28:38 +0000 Subject: [PATCH 4/7] Revert "[Doc] Adding reference to subscription and slicing operations on sequence type definition" This reverts commit 81ce055b55c9c9625dee645a1af2debe9ffc57bc. --- Doc/reference/datamodel.rst | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 1b6c191678ad6c..9c66e3e2c495e2 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -296,14 +296,26 @@ Sequences single: item selection single: subscription -These represent finite ordered sets indexed by non-negative numbers. The +These represent finite ordered sets indexed by integer numbers. The built-in function :func:`len` returns the number of items of a sequence. When -the length of a sequence is *n*, the index set contains the numbers 0, -1, 2, ..., *n*-1. +the length of a sequence is *n*, the index set contains the numbers -*n*, +-*n*+1, -*n*+2, ..., 0, 1, ..., *n*-1. -Sequences are instances of a :ref:`container class `, so they -support the :ref:`subscription ` and :ref:`slicing ` -operations. +For non-negative numbers, the item *i* of sequence *a* is selected by ``a[i]``. + +For negative numbers, -1 is the last item and -2 is the penultimate (next to +last) item and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. + +.. index:: single: slicing + +Sequences also support slicing: ``a[i:j]`` selects all items with index *k* such +that *i* ``<=`` *k* ``<`` *j*. When used as an expression, a slice is a +sequence of the same type. This implies that the index set is renumbered so +that it starts at 0. + +Some sequences also support "extended slicing" with a third "step" parameter: +``a[i:j:k]`` selects all items of *a* with index *x* where ``x = i + n*k``, *n* +``>=`` ``0`` and *i* ``<=`` *x* ``<`` *j*. Sequences are distinguished according to their mutability: From 1ff9567db050ad349b6f27200721eac43d88c02a Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 25 Mar 2024 19:28:56 +0000 Subject: [PATCH 5/7] Revert "[Doc] Add information about sequence indexes values" This reverts commit 3d22a1e61fea797ade15bede4c505a8190171ba6. --- Doc/reference/datamodel.rst | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 9c66e3e2c495e2..f4658c47995df5 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -298,13 +298,8 @@ Sequences These represent finite ordered sets indexed by integer numbers. The built-in function :func:`len` returns the number of items of a sequence. When -the length of a sequence is *n*, the index set contains the numbers -*n*, --*n*+1, -*n*+2, ..., 0, 1, ..., *n*-1. - -For non-negative numbers, the item *i* of sequence *a* is selected by ``a[i]``. - -For negative numbers, -1 is the last item and -2 is the penultimate (next to -last) item and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. +the length of a sequence is *n*, the index set contains the numbers 0, 1, +..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. .. index:: single: slicing From fd010a3a21faf6d98259d6c53926ec8ec15a763c Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 25 Mar 2024 19:29:11 +0000 Subject: [PATCH 6/7] Revert "[Doc] Fixing sequence index range" This reverts commit ad9224fb83365ee6314fa16699f384a772b74708. --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index f4658c47995df5..75b656f385d34b 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -296,7 +296,7 @@ Sequences single: item selection single: subscription -These represent finite ordered sets indexed by integer numbers. The +These represent finite ordered sets indexed by non-negative numbers. The built-in function :func:`len` returns the number of items of a sequence. When the length of a sequence is *n*, the index set contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. From d7af24c0d673b2d45f089a86ec4845c4a5ba306d Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 25 Mar 2024 19:52:34 +0000 Subject: [PATCH 7/7] [Doc] Make clearest information about sequences negative indexes --- Doc/reference/datamodel.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 75b656f385d34b..bc835b8e30cb29 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -299,14 +299,17 @@ Sequences These represent finite ordered sets indexed by non-negative numbers. The built-in function :func:`len` returns the number of items of a sequence. When the length of a sequence is *n*, the index set contains the numbers 0, 1, -..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. +..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. Some sequences, +including built-in sequences, interpret negative subscripts by adding the +sequence length. For example, ``a[-2]`` equals ``a[n-2]``, the second to last +item of sequence a with length ``n``. .. index:: single: slicing Sequences also support slicing: ``a[i:j]`` selects all items with index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an expression, a slice is a -sequence of the same type. This implies that the index set is renumbered so -that it starts at 0. +sequence of the same type. The comment above about negative indexes also applies +to negative slice positions. Some sequences also support "extended slicing" with a third "step" parameter: ``a[i:j:k]`` selects all items of *a* with index *x* where ``x = i + n*k``, *n*