Skip to content

Commit e76a4ab

Browse files
Doc: simplify sorted() example in sorting howto
1 parent 35cccf2 commit e76a4ab

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

Doc/howto/sorting.rst

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,9 @@ lost:
2424

2525
.. doctest::
2626

27-
>>> sorted([5, 2, 3, 1, 4])
28-
[1, 2, 3, 4, 5]
29-
30-
>>> original = [5, 2, 3, 1, 4]
31-
>>> sorted(original) # Returns a new sorted list
32-
[1, 2, 3, 4, 5]
33-
>>> original # Original remains unchanged
34-
[5, 2, 3, 1, 4]
35-
36-
>>> # To keep the sorted result, assign it to a variable
37-
>>> sorted_list = sorted(original)
38-
>>> sorted_list
27+
>>> integers = [5, 2, 3, 1, 4]
28+
>>> sorted_integers = sorted(integers)
29+
>>> sorted_integers
3930
[1, 2, 3, 4, 5]
4031

4132
You can also use the :meth:`list.sort` method. It modifies the list
@@ -46,7 +37,7 @@ more efficient.
4637
.. doctest::
4738

4839
>>> a = [5, 2, 3, 1, 4]
49-
>>> a.sort() # Modifies 'a' in-place, returns None
40+
>>> a.sort()
5041
>>> a
5142
[1, 2, 3, 4, 5]
5243

0 commit comments

Comments
 (0)