Skip to content

Commit 0327131

Browse files
author
dagangtj
committed
docs: Simplify "More on Lists" section in tutorial
Simplify the "More on Lists" section by replacing detailed .. method:: directives with concise descriptions and links to the Library Reference. This change: - Removes duplicated method definitions that already exist in the Library Reference - Uses a consistent format matching other built-in types in the tutorial - Adds clear links to the Library Reference for complete documentation Fixes: #146487
1 parent 6009309 commit 0327131

File tree

1 file changed

+17
-67
lines changed

1 file changed

+17
-67
lines changed

Doc/tutorial/datastructures.rst

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,34 @@ More on Lists
1515
The :ref:`list <typesseq-list>` data type has some more methods. Here are all
1616
of the methods of list objects:
1717

18-
.. method:: list.append(x)
19-
:noindex:
18+
* :meth:`~list.append` --- Add an item to the end of the list.
2019

21-
Add an item to the end of the list. Similar to ``a[len(a):] = [x]``.
20+
* :meth:`~list.extend` --- Extend the list by appending all the items from the
21+
iterable.
2222

23+
* :meth:`~list.insert` --- Insert an item at a given position.
2324

24-
.. method:: list.extend(iterable)
25-
:noindex:
25+
* :meth:`~list.remove` --- Remove the first item from the list whose value is
26+
equal to *x*.
2627

27-
Extend the list by appending all the items from the iterable. Similar to
28-
``a[len(a):] = iterable``.
28+
* :meth:`~list.pop` --- Remove the item at the given position in the list,
29+
and return it.
2930

31+
* :meth:`~list.clear` --- Remove all items from the list.
3032

31-
.. method:: list.insert(i, x)
32-
:noindex:
33+
* :meth:`~list.index` --- Return zero-based index of the first occurrence of
34+
*x* in the list.
3335

34-
Insert an item at a given position. The first argument is the index of the
35-
element before which to insert, so ``a.insert(0, x)`` inserts at the front of
36-
the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``.
36+
* :meth:`~list.count` --- Return the number of times *x* appears in the list.
3737

38+
* :meth:`~list.sort` --- Sort the items of the list in place.
3839

39-
.. method:: list.remove(x)
40-
:noindex:
40+
* :meth:`~list.reverse` --- Reverse the elements of the list in place.
4141

42-
Remove the first item from the list whose value is equal to *x*. It raises a
43-
:exc:`ValueError` if there is no such item.
42+
* :meth:`~list.copy` --- Return a shallow copy of the list.
4443

45-
46-
.. method:: list.pop([i])
47-
:noindex:
48-
49-
Remove the item at the given position in the list, and return it. If no index
50-
is specified, ``a.pop()`` removes and returns the last item in the list.
51-
It raises an :exc:`IndexError` if the list is empty or the index is
52-
outside the list range.
53-
54-
55-
.. method:: list.clear()
56-
:noindex:
57-
58-
Remove all items from the list. Similar to ``del a[:]``.
59-
60-
61-
.. method:: list.index(x[, start[, end]])
62-
:noindex:
63-
64-
Return zero-based index of the first occurrence of *x* in the list.
65-
Raises a :exc:`ValueError` if there is no such item.
66-
67-
The optional arguments *start* and *end* are interpreted as in the slice
68-
notation and are used to limit the search to a particular subsequence of
69-
the list. The returned index is computed relative to the beginning of the full
70-
sequence rather than the *start* argument.
71-
72-
73-
.. method:: list.count(x)
74-
:noindex:
75-
76-
Return the number of times *x* appears in the list.
77-
78-
79-
.. method:: list.sort(*, key=None, reverse=False)
80-
:noindex:
81-
82-
Sort the items of the list in place (the arguments can be used for sort
83-
customization, see :func:`sorted` for their explanation).
84-
85-
86-
.. method:: list.reverse()
87-
:noindex:
88-
89-
Reverse the elements of the list in place.
90-
91-
92-
.. method:: list.copy()
93-
:noindex:
94-
95-
Return a shallow copy of the list. Similar to ``a[:]``.
44+
For complete descriptions of these methods, see the :ref:`list type
45+
<typesseq-list>` documentation in the Library Reference.
9646

9747

9848
An example that uses most of the list methods::

0 commit comments

Comments
 (0)