chunk_id
stringlengths
36
36
source
stringclasses
35 values
source_url
stringlengths
0
290
upstream_license
stringclasses
1 value
document_id
stringlengths
36
36
chunk_index
int64
0
324k
retrieved_at
stringclasses
2 values
chunker_version
stringclasses
4 values
content_hash
stringlengths
15
64
content
stringlengths
50
44.7k
namespace
stringclasses
9 values
source_name
stringclasses
35 values
raw_text
stringlengths
50
44.7k
cleaned_text
stringlengths
50
44.7k
tags
stringclasses
49 values
collection_name
stringclasses
11 values
52916a2c-3aa8-4a3c-90ad-4259090bed65
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,948
supabase-export-v2
dd08e6c8094da07a
a possibly non-existent key, use the :meth:`~dict.get` method instead, which returns ``None`` (or a specified default value) if the key is not in the dictionary. Performing ``list(d)`` on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use ``sorted(d)`...
trusted_official_docs
CPython Docs
a possibly non-existent key, use the :meth:`~dict.get` method instead, which returns ``None`` (or a specified default value) if the key is not in the dictionary. Performing ``list(d)`` on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use ``sorted(d)`...
a possibly non-existent key, use the :meth:`~dict.get` method instead, which returns ``None`` (or a specified default value) if the key is not in the dictionary. Performing ``list(d)`` on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use ``sorted(d)`...
python, official-docs, cpython, P0
Local_Trusted_Corpus
54eb66cc-c85c-4bcf-b81f-c0a9375c86ca
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,884
supabase-export-v2
77fbaabe0db146c4
and it's equivalent to:: >>> combs = [] >>> for x in [1,2,3]: ... for y in [3,1,4]: ... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
trusted_official_docs
CPython Docs
and it's equivalent to:: >>> combs = [] >>> for x in [1,2,3]: ... for y in [3,1,4]: ... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
and it's equivalent to:: >>> combs = [] >>> for x in [1,2,3]: ... for y in [3,1,4]: ... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
python, official-docs, cpython, P0
Local_Trusted_Corpus
55fe75d2-f9a9-47fa-b0c2-bb42b09a8380
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,927
supabase-export-v2
4f95beda781a74f5
not possible to assign to the individual items of a tuple, however it is possible to create tuples which contain mutable objects, such as lists. Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples are :term:`immutable`, and usually contain a heterogene...
trusted_official_docs
CPython Docs
not possible to assign to the individual items of a tuple, however it is possible to create tuples which contain mutable objects, such as lists. Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples are :term:`immutable`, and usually contain a heterogene...
not possible to assign to the individual items of a tuple, however it is possible to create tuples which contain mutable objects, such as lists. Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples are :term:`immutable`, and usually contain a heterogene...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5670eba9-b4a6-4c66-b3af-c1b7f17c6c7f
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,898
supabase-export-v2
582835a773474b7b
in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to:: >>> transposed = [] >>> for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
trusted_official_docs
CPython Docs
in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to:: >>> transposed = [] >>> for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to:: >>> transposed = [] >>> for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
python, official-docs, cpython, P0
Local_Trusted_Corpus
58fd815e-31de-47b2-a536-0b8adb495da0
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,869
supabase-export-v2
942752257f186125
fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one). To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example::
trusted_official_docs
CPython Docs
fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one). To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example::
fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one). To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example::
python, official-docs, cpython, P0
Local_Trusted_Corpus
5c10c285-efa7-4974-81ab-b7de9eeafb2c
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,988
supabase-export-v2
ccc6c7d0c7ede289
of the other, the shorter sequence is the smaller (lesser) one. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. Some examples of comparisons between sequences of the same type::
trusted_official_docs
CPython Docs
of the other, the shorter sequence is the smaller (lesser) one. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. Some examples of comparisons between sequences of the same type::
of the other, the shorter sequence is the smaller (lesser) one. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. Some examples of comparisons between sequences of the same type::
python, official-docs, cpython, P0
Local_Trusted_Corpus
5dd432d3-8441-4a0a-86ad-08751bad6102
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,989
supabase-export-v2
7e6b34de28adde4c
Some examples of comparisons between sequences of the same type:: (1, 2, 3) < (1, 2, 4) [1, 2, 3] < [1, 2, 4] 'ABC' < 'C' < 'Pascal' < 'Python' (1, 2, 3, 4) < (1, 2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
trusted_official_docs
CPython Docs
Some examples of comparisons between sequences of the same type:: (1, 2, 3) < (1, 2, 4) [1, 2, 3] < [1, 2, 4] 'ABC' < 'C' < 'Pascal' < 'Python' (1, 2, 3, 4) < (1, 2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
Some examples of comparisons between sequences of the same type:: (1, 2, 3) < (1, 2, 4) [1, 2, 3] < [1, 2, 4] 'ABC' < 'C' < 'Pascal' < 'Python' (1, 2, 3, 4) < (1, 2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
python, official-docs, cpython, P0
Local_Trusted_Corpus
5f07d3d6-795d-42a0-a9be-499371c756c6
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,868
supabase-export-v2
0da52bc3811078d8
Using Lists as Queues --------------------- It is also possible to use a list as a queue, where the first element added is the first element retrieved ("first-in, first-out"); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginnin...
trusted_official_docs
CPython Docs
Using Lists as Queues --------------------- It is also possible to use a list as a queue, where the first element added is the first element retrieved ("first-in, first-out"); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginnin...
Using Lists as Queues --------------------- It is also possible to use a list as a queue, where the first element added is the first element retrieved ("first-in, first-out"); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginnin...
python, official-docs, cpython, P0
Local_Trusted_Corpus
61a5979b-2a86-48ba-afb8-a58a18104a70
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,970
supabase-export-v2
bcdedf7f86a79028
>>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1 To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
trusted_official_docs
CPython Docs
>>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1 To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
>>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1 To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
66a020fa-bbc5-4d0c-b17f-c5ded061f0ec
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,940
supabase-export-v2
3b769b6f1ac9040b
both a and b {'a', 'c'} >>> a ^ b # letters in a or b but not both {'r', 'd', 'b', 'm', 'z', 'l'} Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking::
trusted_official_docs
CPython Docs
both a and b {'a', 'c'} >>> a ^ b # letters in a or b but not both {'r', 'd', 'b', 'm', 'z', 'l'} Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking::
both a and b {'a', 'c'} >>> a ^ b # letters in a or b but not both {'r', 'd', 'b', 'm', 'z', 'l'} Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking::
python, official-docs, cpython, P0
Local_Trusted_Corpus
6aa4500d-9d4d-42a3-a185-12c3d48f909a
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,982
supabase-export-v2
6f0c5c991f91b7ba
and not B or C`` is equivalent to ``(A and (not B)) or C``. As always, parentheses can be used to express the desired composition. The Boolean operators ``and`` and ``or`` are so-called *short-circuit* operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined...
trusted_official_docs
CPython Docs
and not B or C`` is equivalent to ``(A and (not B)) or C``. As always, parentheses can be used to express the desired composition. The Boolean operators ``and`` and ``or`` are so-called *short-circuit* operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined...
and not B or C`` is equivalent to ``(A and (not B)) or C``. As always, parentheses can be used to express the desired composition. The Boolean operators ``and`` and ``or`` are so-called *short-circuit* operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6d2a529d-3cea-4d34-bfd2-16c85160e04b
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,897
supabase-export-v2
6115675157ff9cd2
>>> [[row[i] for row in matrix] for i in range(4)] [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] As we saw in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to::
trusted_official_docs
CPython Docs
>>> [[row[i] for row in matrix] for i in range(4)] [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] As we saw in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to::
>>> [[row[i] for row in matrix] for i in range(4)] [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] As we saw in the previous section, the inner list comprehension is evaluated in the context of the :keyword:`for` that follows it, so this example is equivalent to::
python, official-docs, cpython, P0
Local_Trusted_Corpus
6d70aafa-300c-4ec2-8612-18ae687b9c50
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,893
supabase-export-v2
d81f3401443b8a25
The initial expression in a list comprehension can be any arbitrary expression, including another list comprehension. Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4::
trusted_official_docs
CPython Docs
The initial expression in a list comprehension can be any arbitrary expression, including another list comprehension. Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4::
The initial expression in a list comprehension can be any arbitrary expression, including another list comprehension. Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4::
python, official-docs, cpython, P0
Local_Trusted_Corpus
723fa8e4-7909-432f-b79d-ae78aa271820
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,881
supabase-export-v2
2b555c94dadbd857
which is more concise and readable. A list comprehension consists of brackets containing an expression followed by a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!if` clauses. The result will be a new list resulting from evaluating the expression in the context of the :keyword:`!for` and :keyw...
trusted_official_docs
CPython Docs
which is more concise and readable. A list comprehension consists of brackets containing an expression followed by a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!if` clauses. The result will be a new list resulting from evaluating the expression in the context of the :keyword:`!for` and :keyw...
which is more concise and readable. A list comprehension consists of brackets containing an expression followed by a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!if` clauses. The result will be a new list resulting from evaluating the expression in the context of the :keyword:`!for` and :keyw...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7318be67-a0c3-4437-a21b-4f97130e2163
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,888
supabase-export-v2
590f015cd8b3e3d6
x**2 for x in range(6)] File "<stdin>", line 1 [x, x**2 for x in range(6)] ^^^^^^^ SyntaxError: did you forget parentheses around the comprehension target? >>> # flatten a list using a listcomp with two 'for' >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
trusted_official_docs
CPython Docs
x**2 for x in range(6)] File "<stdin>", line 1 [x, x**2 for x in range(6)] ^^^^^^^ SyntaxError: did you forget parentheses around the comprehension target? >>> # flatten a list using a listcomp with two 'for' >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
x**2 for x in range(6)] File "<stdin>", line 1 [x, x**2 for x in range(6)] ^^^^^^^ SyntaxError: did you forget parentheses around the comprehension target? >>> # flatten a list using a listcomp with two 'for' >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
python, official-docs, cpython, P0
Local_Trusted_Corpus
73c43e8b-e035-4701-9311-7de378e31896
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,964
supabase-export-v2
84fa076afbfb6fd3
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'} >>> for k, v in knights.items(): ... print(k, v) ... gallahad the pure robin the brave When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. ::
trusted_official_docs
CPython Docs
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'} >>> for k, v in knights.items(): ... print(k, v) ... gallahad the pure robin the brave When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. ::
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'} >>> for k, v in knights.items(): ... print(k, v) ... gallahad the pure robin the brave When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
78019fbc-4c09-4d45-8f2c-e03c8b9895d1
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,944
supabase-export-v2
f0b089774dd6200c
Dictionaries ============ Another useful data type built into Python is the *dictionary* (see :ref:`typesmapping`). Dictionaries are sometimes found in other languages as "associative memories" or "associative arrays". Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by *keys*, which ...
trusted_official_docs
CPython Docs
Dictionaries ============ Another useful data type built into Python is the *dictionary* (see :ref:`typesmapping`). Dictionaries are sometimes found in other languages as "associative memories" or "associative arrays". Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by *keys*, which ...
Dictionaries ============ Another useful data type built into Python is the *dictionary* (see :ref:`typesmapping`). Dictionaries are sometimes found in other languages as "associative memories" or "associative arrays". Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by *keys*, which ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
793d04a5-a2d7-467b-bb93-1b74a0a05384
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,951
supabase-export-v2
0fe8bfca77709037
'guido': 4127, 'irv': 4127} >>> list(tel) ['jack', 'guido', 'irv'] >>> sorted(tel) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False The :func:`dict` constructor builds dictionaries directly from sequences of key-value pairs::
trusted_official_docs
CPython Docs
'guido': 4127, 'irv': 4127} >>> list(tel) ['jack', 'guido', 'irv'] >>> sorted(tel) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False The :func:`dict` constructor builds dictionaries directly from sequences of key-value pairs::
'guido': 4127, 'irv': 4127} >>> list(tel) ['jack', 'guido', 'irv'] >>> sorted(tel) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False The :func:`dict` constructor builds dictionaries directly from sequences of key-value pairs::
python, official-docs, cpython, P0
Local_Trusted_Corpus
7fb6d16c-f1dc-4151-bdcb-7862d9f97393
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,926
supabase-export-v2
1797ac0319851119
2, 1]) >>> # they support unpacking just like lists: >>> x = [1, 2, 3] >>> 0, *x, 4 (0, 1, 2, 3, 4) As you see, on output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway...
trusted_official_docs
CPython Docs
2, 1]) >>> # they support unpacking just like lists: >>> x = [1, 2, 3] >>> 0, *x, 4 (0, 1, 2, 3, 4) As you see, on output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway...
2, 1]) >>> # they support unpacking just like lists: >>> x = [1, 2, 3] >>> 0, *x, 4 (0, 1, 2, 3, 4) As you see, on output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8c51b9e7-c808-49a7-a5fc-7031e317550e
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,870
supabase-export-v2
e14e357771c8941b
To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example:: >>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("Terry") # Terry arrives >>> queue.append("Graham") # Graham arrives >>> queue.popleft...
trusted_official_docs
CPython Docs
To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example:: >>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("Terry") # Terry arrives >>> queue.append("Graham") # Graham arrives >>> queue.popleft...
To implement a queue, use :class:`collections.deque` which was designed to have fast appends and pops from both ends. For example:: >>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("Terry") # Terry arrives >>> queue.append("Graham") # Graham arrives >>> queue.popleft...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8da32b36-bc6d-4ccb-801b-1ce3e4975ff4
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,984
supabase-export-v2
816a80b1535d0284
It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, :: >>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim'
trusted_official_docs
CPython Docs
It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, :: >>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim'
It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, :: >>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim'
python, official-docs, cpython, P0
Local_Trusted_Corpus
8e5efdf4-a16b-4904-8c90-84208744ba40
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,875
supabase-export-v2
40cc31166f92df8a
For example, assume we want to create a list of squares, like:: >>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
trusted_official_docs
CPython Docs
For example, assume we want to create a list of squares, like:: >>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
For example, assume we want to create a list of squares, like:: >>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
python, official-docs, cpython, P0
Local_Trusted_Corpus
91520f1c-2cd9-4e26-bcbd-dd653df6948e
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,990
supabase-export-v2
4bc645c631419db3
2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4) Note that comparing objects of different types with ``<`` or ``>`` is legal provided that the objects have appropriate comparison methods. For example, mixed numeric types are compared according to their numeric value,...
trusted_official_docs
CPython Docs
2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4) Note that comparing objects of different types with ``<`` or ``>`` is legal provided that the objects have appropriate comparison methods. For example, mixed numeric types are compared according to their numeric value,...
2, 4) (1, 2) < (1, 2, -1) (1, 2, 3) == (1.0, 2.0, 3.0) (1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4) Note that comparing objects of different types with ``<`` or ``>`` is legal provided that the objects have appropriate comparison methods. For example, mixed numeric types are compared according to their numeric value,...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9250a720-2a1f-4a2e-ac35-ec42fa9dd673
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,972
supabase-export-v2
e195f466bbf75953
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for i in sorted(basket): ... print(i) ... apple apple banana orange orange pear Using :func:`set` on a sequence eliminates duplicate elements. The use of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop o...
trusted_official_docs
CPython Docs
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for i in sorted(basket): ... print(i) ... apple apple banana orange orange pear Using :func:`set` on a sequence eliminates duplicate elements. The use of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop o...
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for i in sorted(basket): ... print(i) ... apple apple banana orange orange pear Using :func:`set` on a sequence eliminates duplicate elements. The use of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop o...
python, official-docs, cpython, P0
Local_Trusted_Corpus
93d7b464-3058-4972-b0e4-1f827478c036
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,916
supabase-export-v2
45d41470396b4237
The :keyword:`!del` statement ============================= There is a way to remove an item from a list given its index instead of its value: the :keyword:`del` statement. This differs from the :meth:`~list.pop` method which returns a value. The :keyword:`!del` statement can also be used to remove slices from a list o...
trusted_official_docs
CPython Docs
The :keyword:`!del` statement ============================= There is a way to remove an item from a list given its index instead of its value: the :keyword:`del` statement. This differs from the :meth:`~list.pop` method which returns a value. The :keyword:`!del` statement can also be used to remove slices from a list o...
The :keyword:`!del` statement ============================= There is a way to remove an item from a list given its index instead of its value: the :keyword:`del` statement. This differs from the :meth:`~list.pop` method which returns a value. The :keyword:`!del` statement can also be used to remove slices from a list o...
python, official-docs, cpython, P0
Local_Trusted_Corpus
95a4cef0-4801-4c61-a0d2-969993dafe63
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,923
supabase-export-v2
e08e3b9fe070b3cb
Tuples and Sequences ==================== We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of *sequence* data types (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard...
trusted_official_docs
CPython Docs
Tuples and Sequences ==================== We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of *sequence* data types (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard...
Tuples and Sequences ==================== We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of *sequence* data types (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard...
python, official-docs, cpython, P0
Local_Trusted_Corpus
95b2786e-5a52-4612-82fd-c15ee9e9eae2
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,945
supabase-export-v2
41c959d5c2b32121
key. You can't use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like :meth:`~list.append` and :meth:`~list.extend`. It is best to think of a dictionary as a set of *key: value* pairs, with the requirement that the keys are unique (within one dictionary). A p...
trusted_official_docs
CPython Docs
key. You can't use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like :meth:`~list.append` and :meth:`~list.extend`. It is best to think of a dictionary as a set of *key: value* pairs, with the requirement that the keys are unique (within one dictionary). A p...
key. You can't use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like :meth:`~list.append` and :meth:`~list.extend`. It is best to think of a dictionary as a set of *key: value* pairs, with the requirement that the keys are unique (within one dictionary). A p...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9853da7b-a82b-4f0e-93be-c9ae5a4834c5
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,935
supabase-export-v2
9cf75e80eb9ccf0b
no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the :func:`set` function can be used to create sets. Note: to create an empty set you have to u...
trusted_official_docs
CPython Docs
no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the :func:`set` function can be used to create sets. Note: to create an empty set you have to u...
no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the :func:`set` function can be used to create sets. Note: to create an empty set you have to u...
python, official-docs, cpython, P0
Local_Trusted_Corpus
99f93d96-afeb-448a-8458-883be6320ced
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,913
supabase-export-v2
7cffea3986e99bc8
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}] >>> [*element for element in x] [1, 2, 3, 'c', 'a', 't', 'spam'] But if the objects in ``x`` are not iterable, this expression would again raise an exception.
trusted_official_docs
CPython Docs
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}] >>> [*element for element in x] [1, 2, 3, 'c', 'a', 't', 'spam'] But if the objects in ``x`` are not iterable, this expression would again raise an exception.
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}] >>> [*element for element in x] [1, 2, 3, 'c', 'a', 't', 'spam'] But if the objects in ``x`` are not iterable, this expression would again raise an exception.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9aa801ac-2665-48c6-a823-be5c51eb74e3
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,958
supabase-export-v2
a5511b0b3a7ba3d9
= [odds, evens, {0: 0}] >>> {**i for i in all_values} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments::
trusted_official_docs
CPython Docs
= [odds, evens, {0: 0}] >>> {**i for i in all_values} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments::
= [odds, evens, {0: 0}] >>> {**i for i in all_values} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments::
python, official-docs, cpython, P0
Local_Trusted_Corpus
9c6ca810-43b2-4f1e-9fb4-9f6e96319126
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,841
supabase-export-v2
760c3ef49facd8c0
index of the element before which to insert, so ``a.insert(0, x)`` inserts at the front of the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. .. method:: list.remove(value, /) :noindex:
trusted_official_docs
CPython Docs
index of the element before which to insert, so ``a.insert(0, x)`` inserts at the front of the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. .. method:: list.remove(value, /) :noindex:
index of the element before which to insert, so ``a.insert(0, x)`` inserts at the front of the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. .. method:: list.remove(value, /) :noindex:
python, official-docs, cpython, P0
Local_Trusted_Corpus
a3a56751-ab2a-426f-8819-f6cb104c6335
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,973
supabase-export-v2
664ad9136ba778f4
of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop over unique elements of the sequence in sorted order. :: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear
trusted_official_docs
CPython Docs
of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop over unique elements of the sequence in sorted order. :: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear
of :func:`sorted` in combination with :func:`set` over a sequence is an idiomatic way to loop over unique elements of the sequence in sorted order. :: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear
python, official-docs, cpython, P0
Local_Trusted_Corpus
a49c827e-31b4-425e-acca-58d0c8ec1356
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,908
supabase-export-v2
8a3cb4f39e32d22c
This only works if the expression following the ``*`` evaluates to an iterable object; trying to unpack a non-iterable object will raise an exception:: >>> x = 1 >>> [0, *x, 2, 3, 4] Traceback (most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an...
trusted_official_docs
CPython Docs
This only works if the expression following the ``*`` evaluates to an iterable object; trying to unpack a non-iterable object will raise an exception:: >>> x = 1 >>> [0, *x, 2, 3, 4] Traceback (most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an...
This only works if the expression following the ``*`` evaluates to an iterable object; trying to unpack a non-iterable object will raise an exception:: >>> x = 1 >>> [0, *x, 2, 3, 4] Traceback (most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a5f9a3e0-2ad8-453f-8187-cbd7a924cac9
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,887
supabase-export-v2
4c6811a524f93aa6
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), it must be parenthesized. :: >>> vec = [-4, -2, 0, 2, 4] >>> # create a new list with the values doubled >>> [x*2 for x in vec] [-8, -4, 0, 4, 8] >>> # filter the list to exclude negative numbers >>> [x for x in vec if x >= 0] [0, 2, 4] ...
trusted_official_docs
CPython Docs
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), it must be parenthesized. :: >>> vec = [-4, -2, 0, 2, 4] >>> # create a new list with the values doubled >>> [x*2 for x in vec] [-8, -4, 0, 4, 8] >>> # filter the list to exclude negative numbers >>> [x for x in vec if x >= 0] [0, 2, 4] ...
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), it must be parenthesized. :: >>> vec = [-4, -2, 0, 2, 4] >>> # create a new list with the values doubled >>> [x*2 for x in vec] [-8, -4, 0, 4, 8] >>> # filter the list to exclude negative numbers >>> [x for x in vec if x >= 0] [0, 2, 4] ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a637e01d-6fda-4f5f-a8dd-adbcf836159e
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,900
supabase-export-v2
9daa360a0d099b96
which, in turn, is the same as:: >>> transposed = [] >>> for i in range(4): ... # the following 3 lines implement the nested listcomp ... transposed_row = [] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, ...
trusted_official_docs
CPython Docs
which, in turn, is the same as:: >>> transposed = [] >>> for i in range(4): ... # the following 3 lines implement the nested listcomp ... transposed_row = [] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, ...
which, in turn, is the same as:: >>> transposed = [] >>> for i in range(4): ... # the following 3 lines implement the nested listcomp ... transposed_row = [] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a6e3057e-5141-49d1-b73d-7fcc78763d0d
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,985
supabase-export-v2
793a9320786d2077
>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim' Note that in Python, unlike C, assignment inside expressions must be done explicitly with the :ref:`walrus operator <why-can-t-i-use-an-assignment-in-an-expression>` ``:=``. This avoids ...
trusted_official_docs
CPython Docs
>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim' Note that in Python, unlike C, assignment inside expressions must be done explicitly with the :ref:`walrus operator <why-can-t-i-use-an-assignment-in-an-expression>` ``:=``. This avoids ...
>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance' >>> non_null = string1 or string2 or string3 >>> non_null 'Trondheim' Note that in Python, unlike C, assignment inside expressions must be done explicitly with the :ref:`walrus operator <why-can-t-i-use-an-assignment-in-an-expression>` ``:=``. This avoids ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a81dea52-0699-4ce4-974f-4a7655b7394b
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,876
supabase-export-v2
201cf077c9aef7dc
>>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Note that this creates (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
trusted_official_docs
CPython Docs
>>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Note that this creates (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
>>> squares = [] >>> for x in range(10): ... squares.append(x**2) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Note that this creates (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
python, official-docs, cpython, P0
Local_Trusted_Corpus
ae833035-4246-4c92-8f89-b70fd48ff02f
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,980
supabase-export-v2
0f9672d5b8903a9c
compare whether two objects are really the same object. All comparison operators have the same priority, which is lower than that of all numerical operators. Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``.
trusted_official_docs
CPython Docs
compare whether two objects are really the same object. All comparison operators have the same priority, which is lower than that of all numerical operators. Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``.
compare whether two objects are really the same object. All comparison operators have the same priority, which is lower than that of all numerical operators. Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
b1cc7432-ffab-4611-a002-3d4e2b19f839
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,932
supabase-export-v2
fc85993b37a41124
>>> x, y, z = t This is called, appropriately enough, *sequence unpacking* and works for any sequence on the right-hand side. Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence. Note that multiple assignment is really just a combination...
trusted_official_docs
CPython Docs
>>> x, y, z = t This is called, appropriately enough, *sequence unpacking* and works for any sequence on the right-hand side. Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence. Note that multiple assignment is really just a combination...
>>> x, y, z = t This is called, appropriately enough, *sequence unpacking* and works for any sequence on the right-hand side. Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence. Note that multiple assignment is really just a combination...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b53e13be-6670-4eaf-b395-209658be7b10
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,968
supabase-export-v2
ba690b024d6dd57b
... What is your name? It is lancelot. What is your quest? It is the holy grail. What is your favorite color? It is blue. To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. ::
trusted_official_docs
CPython Docs
... What is your name? It is lancelot. What is your quest? It is the holy grail. What is your favorite color? It is blue. To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. ::
... What is your name? It is lancelot. What is your quest? It is the holy grail. What is your favorite color? It is blue. To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
b6317872-ac44-433c-a2e7-a296d40a42fa
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,899
supabase-export-v2
730608ff268efe15
for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] which, in turn, is the same as::
trusted_official_docs
CPython Docs
for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] which, in turn, is the same as::
for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] which, in turn, is the same as::
python, official-docs, cpython, P0
Local_Trusted_Corpus
b95770c5-064e-4463-91c6-6573426779cf
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,956
supabase-export-v2
1102477e4db67525
And dictionary unpacking (via ``**``) can be used to merge multiple dictionaries:: >>> odds = {i: i**2 for i in (1, 3, 5)} >>> evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
trusted_official_docs
CPython Docs
And dictionary unpacking (via ``**``) can be used to merge multiple dictionaries:: >>> odds = {i: i**2 for i in (1, 3, 5)} >>> evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
And dictionary unpacking (via ``**``) can be used to merge multiple dictionaries:: >>> odds = {i: i**2 for i in (1, 3, 5)} >>> evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
python, official-docs, cpython, P0
Local_Trusted_Corpus
baf0faea-9882-4dce-869d-4320d5bd3243
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,983
supabase-export-v2
30fd65bb6850b98b
expression ``C``. When used as a general value and not as a Boolean, the return value of a short-circuit operator is the last evaluated argument. It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, ::
trusted_official_docs
CPython Docs
expression ``C``. When used as a general value and not as a Boolean, the return value of a short-circuit operator is the last evaluated argument. It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, ::
expression ``C``. When used as a general value and not as a Boolean, the return value of a short-circuit operator is the last evaluated argument. It is possible to assign the result of a comparison or other Boolean expression to a variable. For example, ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
bb44ffdd-2e1f-4cd0-b23a-263c02df67dd
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,975
supabase-export-v2
32b34899ec10d7dd
tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. :: >>> import math >>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8] >>> filtered_data = [] >>> for value in raw_data: ... if not math.isnan(value): ... filtered_dat...
trusted_official_docs
CPython Docs
tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. :: >>> import math >>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8] >>> filtered_data = [] >>> for value in raw_data: ... if not math.isnan(value): ... filtered_dat...
tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. :: >>> import math >>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8] >>> filtered_data = [] >>> for value in raw_data: ... if not math.isnan(value): ... filtered_dat...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c1768f87-cddb-465b-929d-89d2abfc4843
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,965
supabase-export-v2
a5c7943c18011f6f
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. :: >>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe
trusted_official_docs
CPython Docs
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. :: >>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the :func:`enumerate` function. :: >>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe
python, official-docs, cpython, P0
Local_Trusted_Corpus
c18a0433-626f-498d-a529-3310c70c997a
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,844
supabase-export-v2
21b12e5521a0e7b0
.. method:: list.pop(index=-1, /) :noindex: Remove the item at the given position in the list, and return it. If no index is specified, ``a.pop()`` removes and returns the last item in the list. It raises an :exc:`IndexError` if the list is empty or the index is outside the list range.
trusted_official_docs
CPython Docs
.. method:: list.pop(index=-1, /) :noindex: Remove the item at the given position in the list, and return it. If no index is specified, ``a.pop()`` removes and returns the last item in the list. It raises an :exc:`IndexError` if the list is empty or the index is outside the list range.
.. method:: list.pop(index=-1, /) :noindex: Remove the item at the given position in the list, and return it. If no index is specified, ``a.pop()`` removes and returns the last item in the list. It raises an :exc:`IndexError` if the list is empty or the index is outside the list range.
python, official-docs, cpython, P0
Local_Trusted_Corpus
c44c7909-28a3-4995-ae9a-647aae802c63
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,967
supabase-export-v2
3cfd2b9ef2995141
To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. :: >>> questions = ['name', 'quest', 'favorite color'] >>> answers = ['lancelot', 'the holy grail', 'blue'] >>> for q, a in zip(questions, answers): ... print('What is your {0}? It is {1}.'.format(q, a)) .....
trusted_official_docs
CPython Docs
To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. :: >>> questions = ['name', 'quest', 'favorite color'] >>> answers = ['lancelot', 'the holy grail', 'blue'] >>> for q, a in zip(questions, answers): ... print('What is your {0}? It is {1}.'.format(q, a)) .....
To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. :: >>> questions = ['name', 'quest', 'favorite color'] >>> answers = ['lancelot', 'the holy grail', 'blue'] >>> for q, a in zip(questions, answers): ... print('What is your {0}? It is {1}.'.format(q, a)) .....
python, official-docs, cpython, P0
Local_Trusted_Corpus
c5a55b4f-5765-4ccd-97e2-00c68283eac8
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,925
supabase-export-v2
fc0aadab554000de
A tuple consists of a number of values separated by commas, for instance:: >>> t = 12345, 54321, 'hello!' >>> t[0] 12345 >>> t (12345, 54321, 'hello!') >>> # Tuples may be nested: >>> u = t, (1, 2, 3, 4, 5) >>> u ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5)) >>> # Tuples are immutable: >>> t[0] = 88888 Traceba...
trusted_official_docs
CPython Docs
A tuple consists of a number of values separated by commas, for instance:: >>> t = 12345, 54321, 'hello!' >>> t[0] 12345 >>> t (12345, 54321, 'hello!') >>> # Tuples may be nested: >>> u = t, (1, 2, 3, 4, 5) >>> u ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5)) >>> # Tuples are immutable: >>> t[0] = 88888 Traceba...
A tuple consists of a number of values separated by commas, for instance:: >>> t = 12345, 54321, 'hello!' >>> t[0] 12345 >>> t (12345, 54321, 'hello!') >>> # Tuples may be nested: >>> u = t, (1, 2, 3, 4, 5) >>> u ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5)) >>> # Tuples are immutable: >>> t[0] = 88888 Traceba...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c87e7ad8-4a33-4a35-ad3c-b262042b5bf6
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,969
supabase-export-v2
17836b297c0c55ad
To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. :: >>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1
trusted_official_docs
CPython Docs
To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. :: >>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1
To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the :func:`reversed` function. :: >>> for i in reversed(range(1, 10, 2)): ... print(i) ... 9 7 5 3 1
python, official-docs, cpython, P0
Local_Trusted_Corpus
cb209c06-60b0-4f1f-8152-ce07957478fb
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,966
supabase-export-v2
963485791285a802
>>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. ::
trusted_official_docs
CPython Docs
>>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. ::
>>> for i, v in enumerate(['tic', 'tac', 'toe']): ... print(i, v) ... 0 tic 1 tac 2 toe To loop over two or more sequences at the same time, the entries can be paired with the :func:`zip` function. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
cc382010-4ef2-4ecc-b993-7763f1d6c603
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,901
supabase-export-v2
a5e73d1be3f98611
[] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
trusted_official_docs
CPython Docs
[] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
[] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
python, official-docs, cpython, P0
Local_Trusted_Corpus
d80c39a2-6ba8-4941-aa39-93ebf601e385
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,938
supabase-export-v2
2923cbf2a5b52345
Here is a brief demonstration:: >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} >>> print(basket) # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
trusted_official_docs
CPython Docs
Here is a brief demonstration:: >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} >>> print(basket) # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
Here is a brief demonstration:: >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} >>> print(basket) # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
python, official-docs, cpython, P0
Local_Trusted_Corpus
d81a86ad-d4df-4055-a866-33e7299ca6b2
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,941
supabase-export-v2
dd1aa0cfb7dec227
Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking:: >>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'}
trusted_official_docs
CPython Docs
Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking:: >>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'}
Similarly to :ref:`list comprehensions <tut-listcomps>`, set comprehensions are also supported, including comprehensions with unpacking:: >>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'}
python, official-docs, cpython, P0
Local_Trusted_Corpus
db7066a9-31d7-46dd-a660-b1658011aba6
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,954
supabase-export-v2
4e02d7c9264ceb55
In addition, dict comprehensions can be used to create dictionaries from arbitrary key and value expressions:: >>> {x: x**2 for x in (2, 4, 6)} {2: 4, 4: 16, 6: 36}
trusted_official_docs
CPython Docs
In addition, dict comprehensions can be used to create dictionaries from arbitrary key and value expressions:: >>> {x: x**2 for x in (2, 4, 6)} {2: 4, 4: 16, 6: 36}
In addition, dict comprehensions can be used to create dictionaries from arbitrary key and value expressions:: >>> {x: x**2 for x in (2, 4, 6)} {2: 4, 4: 16, 6: 36}
python, official-docs, cpython, P0
Local_Trusted_Corpus
dedaf478-8bae-45e0-98ef-8dd829cc48ab
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,974
supabase-export-v2
0254bcee8bc0ab61
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear It is sometimes tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. ::
trusted_official_docs
CPython Docs
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear It is sometimes tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. ::
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> for f in sorted(set(basket)): ... print(f) ... apple banana orange pear It is sometimes tempting to change a list while you are looping over it; however, it is often simpler and safer to create a new list instead. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
dee23110-365d-41bc-bff6-e7f7e48aaabf
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,905
supabase-export-v2
4582fc4af2f9c537
Unpacking in Lists and List Comprehensions ------------------------------------------ The section on :ref:`tut-unpacking-arguments` describes the use of ``*`` to "unpack" the elements of an iterable object, providing each one separately as an argument to a function. Unpacking can also be used in other contexts, for exa...
trusted_official_docs
CPython Docs
Unpacking in Lists and List Comprehensions ------------------------------------------ The section on :ref:`tut-unpacking-arguments` describes the use of ``*`` to "unpack" the elements of an iterable object, providing each one separately as an argument to a function. Unpacking can also be used in other contexts, for exa...
Unpacking in Lists and List Comprehensions ------------------------------------------ The section on :ref:`tut-unpacking-arguments` describes the use of ``*`` to "unpack" the elements of an iterable object, providing each one separately as an argument to a function. Unpacking can also be used in other contexts, for exa...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e295de0b-6b72-4b69-9a08-98b982e0418f
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,946
supabase-export-v2
7b23ef64a037e239
comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output. The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair ...
trusted_official_docs
CPython Docs
comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output. The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair ...
comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output. The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e357b3ea-d655-4cf1-b5dd-e7825d49f46b
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,947
supabase-export-v2
1769034636163c96
a key:value pair with ``del``. If you store using a key that is already in use, the old value associated with that key is forgotten. Extracting a value for a non-existent key by subscripting (``d[key]``) raises a :exc:`KeyError`. To avoid getting this error when trying to access a possibly non-existent key, use the :me...
trusted_official_docs
CPython Docs
a key:value pair with ``del``. If you store using a key that is already in use, the old value associated with that key is forgotten. Extracting a value for a non-existent key by subscripting (``d[key]``) raises a :exc:`KeyError`. To avoid getting this error when trying to access a possibly non-existent key, use the :me...
a key:value pair with ``del``. If you store using a key that is already in use, the old value associated with that key is forgotten. Extracting a value for a non-existent key by subscripting (``d[key]``) raises a :exc:`KeyError`. To avoid getting this error when trying to access a possibly non-existent key, use the :me...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ebb0b22a-aac8-4872-9a72-28684bd0277f
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,885
supabase-export-v2
2483189f15bd8a6b
... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
trusted_official_docs
CPython Docs
... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
python, official-docs, cpython, P0
Local_Trusted_Corpus
ecc80b79-e6ac-4dab-af4f-67036142ebd7
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,929
supabase-export-v2
1e2466d217f750fa
is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective. For example:: >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
trusted_official_docs
CPython Docs
is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective. For example:: >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective. For example:: >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
python, official-docs, cpython, P0
Local_Trusted_Corpus
ed4d4872-521d-4b13-bc2a-ee846f23e2ba
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,934
supabase-export-v2
7bd413ef5ccaceda
Sets ==== Python also includes a data type for :ref:`sets <types-set>`. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
trusted_official_docs
CPython Docs
Sets ==== Python also includes a data type for :ref:`sets <types-set>`. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Sets ==== Python also includes a data type for :ref:`sets <types-set>`. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
python, official-docs, cpython, P0
Local_Trusted_Corpus
f202e758-b14d-4426-98cd-280fb89fe5f7
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,942
supabase-export-v2
b1e7f35797305bb8
>>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'} >>> fruits = [{'apple', 'avocado', 'apricot'}, {'banana', 'blueberry'}] >>> {*fruit for fruit in fruits} {'blueberry', 'banana', 'avocado', 'apple', 'apricot'}
trusted_official_docs
CPython Docs
>>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'} >>> fruits = [{'apple', 'avocado', 'apricot'}, {'banana', 'blueberry'}] >>> {*fruit for fruit in fruits} {'blueberry', 'banana', 'avocado', 'apple', 'apricot'}
>>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'} >>> fruits = [{'apple', 'avocado', 'apricot'}, {'banana', 'blueberry'}] >>> {*fruit for fruit in fruits} {'blueberry', 'banana', 'avocado', 'apple', 'apricot'}
python, official-docs, cpython, P0
Local_Trusted_Corpus
f6c6ef63-de31-4c12-93e4-c2e7899ed2ed
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,906
supabase-export-v2
eed36ea3a9785b41
a list, prefixing an expression by a ``*`` will unpack the result of that expression, adding each of its elements to the list we're creating:: >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
trusted_official_docs
CPython Docs
a list, prefixing an expression by a ``*`` will unpack the result of that expression, adding each of its elements to the list we're creating:: >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
a list, prefixing an expression by a ``*`` will unpack the result of that expression, adding each of its elements to the list we're creating:: >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
python, official-docs, cpython, P0
Local_Trusted_Corpus
f7258d14-e39f-4083-b1ce-36e2b57b784a
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,909
supabase-export-v2
0e67704811687175
(most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an iterable, not int Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
trusted_official_docs
CPython Docs
(most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an iterable, not int Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
(most recent call last): File "<python-input-1>", line 1, in <module> [0, *x, 2, 3, 4] TypeError: Value after * must be an iterable, not int Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
python, official-docs, cpython, P0
Local_Trusted_Corpus
fa9695d8-8e3b-4250-bb72-77e1f5026348
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,874
supabase-export-v2
2ae6aa3d40d4dd70
of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition. For example, assume we want to create a list of squares, like::
trusted_official_docs
CPython Docs
of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition. For example, assume we want to create a list of squares, like::
of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition. For example, assume we want to create a list of squares, like::
python, official-docs, cpython, P0
Local_Trusted_Corpus
fc824d16-3da0-4148-92e9-84349aeffd9f
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,981
supabase-export-v2
8abbe19e1cd8bf8e
Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``. Comparisons may be combined using the Boolean operators ``and`` and ``or``, and the outcome of a comparison (or of any other Boolean expression) may be negated with ``not``. These have lower p...
trusted_official_docs
CPython Docs
Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``. Comparisons may be combined using the Boolean operators ``and`` and ``or``, and the outcome of a comparison (or of any other Boolean expression) may be negated with ``not``. These have lower p...
Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is less than ``b`` and moreover ``b`` equals ``c``. Comparisons may be combined using the Boolean operators ``and`` and ``or``, and the outcome of a comparison (or of any other Boolean expression) may be negated with ``not``. These have lower p...
python, official-docs, cpython, P0
Local_Trusted_Corpus
fdf3321a-b058-4f54-99aa-4430b3e12cd4
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,894
supabase-export-v2
05ab21796a30a6fa
Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4:: >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
trusted_official_docs
CPython Docs
Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4:: >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4:: >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
python, official-docs, cpython, P0
Local_Trusted_Corpus
ffce619c-077a-4152-869f-da34fe0226cb
CPython Docs
file://datasets/cpython/Doc/tutorial/datastructures.rst
unknown
5af9ff95-89a9-4ede-ba4d-c027dced5b35
53,911
supabase-export-v2
4a37279ffb73e486
[[1, 2, 3], [4, 5, 6], [], [7], [8, 9]] >>> [*element for element in x] [1, 2, 3, 4, 5, 6, 7, 8, 9] Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
trusted_official_docs
CPython Docs
[[1, 2, 3], [4, 5, 6], [], [7], [8, 9]] >>> [*element for element in x] [1, 2, 3, 4, 5, 6, 7, 8, 9] Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
[[1, 2, 3], [4, 5, 6], [], [7], [8, 9]] >>> [*element for element in x] [1, 2, 3, 4, 5, 6, 7, 8, 9] Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
python, official-docs, cpython, P0
Local_Trusted_Corpus
10000bfa-8df1-40f3-b967-88b777ca3730
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
53,997
supabase-export-v2
f62ec789c35affe1
be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is ...
trusted_official_docs
CPython Docs
be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is ...
be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4cd46fd0-b80c-4ee2-b884-d064653676d6
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
54,000
supabase-export-v2
3bcb6d81978872a7
formal definition of the language. To write extensions in C or C++, read :ref:`extending-index` and :ref:`c-api-index`. There are also several books covering Python in depth. This tutorial does not attempt to be comprehensive and cover every single feature, or even every commonly used feature. Instead, it introduces ma...
trusted_official_docs
CPython Docs
formal definition of the language. To write extensions in C or C++, read :ref:`extending-index` and :ref:`c-api-index`. There are also several books covering Python in depth. This tutorial does not attempt to be comprehensive and cover every single feature, or even every commonly used feature. Instead, it introduces ma...
formal definition of the language. To write extensions in C or C++, read :ref:`extending-index` and :ref:`c-api-index`. There are also several books covering Python in depth. This tutorial does not attempt to be comprehensive and cover every single feature, or even every commonly used feature. Instead, it introduces ma...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6b6ccb1a-b3ee-4c17-9423-6abd48dac9e5
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
53,998
supabase-export-v2
629b3d27fb501803
and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications. This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. Be aware that it expects you to have a basic u...
trusted_official_docs
CPython Docs
and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications. This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. Be aware that it expects you to have a basic u...
and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications. This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. Be aware that it expects you to have a basic u...
python, official-docs, cpython, P0
Local_Trusted_Corpus
aac14abc-7385-439d-a4ad-da984991c503
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
53,995
supabase-export-v2
e483d6b2d40b05ea
.. Tip:: This tutorial is designed for *programmers* that are new to the Python language, **not** *beginners* who are new to programming. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's el...
trusted_official_docs
CPython Docs
.. Tip:: This tutorial is designed for *programmers* that are new to the Python language, **not** *beginners* who are new to programming. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's el...
.. Tip:: This tutorial is designed for *programmers* that are new to the Python language, **not** *beginners* who are new to programming. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's el...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ae5774f3-173c-4b8a-87c5-23f1cc1313f2
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
53,996
supabase-export-v2
84c192824f2dc773
and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python website, ht...
trusted_official_docs
CPython Docs
and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python website, ht...
and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python website, ht...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bfcf288c-060b-48bf-ab9c-bed88e01e6a4
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
53,999
supabase-export-v2
98f8589f704d5fa6
It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well. For a description of standard objects and modules, see :ref:`library-index`. :ref:`reference-index` gives a more formal definition of the language. To write extensions ...
trusted_official_docs
CPython Docs
It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well. For a description of standard objects and modules, see :ref:`library-index`. :ref:`reference-index` gives a more formal definition of the language. To write extensions ...
It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well. For a description of standard objects and modules, see :ref:`library-index`. :ref:`reference-index` gives a more formal definition of the language. To write extensions ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c5b528dd-b937-41ff-85dc-19ade19c12af
CPython Docs
file://datasets/cpython/Doc/tutorial/index.rst
unknown
1ede70b3-dd33-4d8f-95b7-6939815cb8e5
54,001
supabase-export-v2
9848b753c0caf103
to read and write Python modules and programs, and you will be ready to learn more about the various Python library modules described in :ref:`library-index`. The :ref:`glossary` is also worth going through.
trusted_official_docs
CPython Docs
to read and write Python modules and programs, and you will be ready to learn more about the various Python library modules described in :ref:`library-index`. The :ref:`glossary` is also worth going through.
to read and write Python modules and programs, and you will be ready to learn more about the various Python library modules described in :ref:`library-index`. The :ref:`glossary` is also worth going through.
python, official-docs, cpython, P0
Local_Trusted_Corpus
041afdc0-b4b7-4d58-b3db-7538ceaeec18
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,101
supabase-export-v2
257699698f45d692
clause extracts from the group exceptions of a certain type while letting all other exceptions propagate to other clauses and eventually to be reraised. :: >>> def f(): ... raise ExceptionGroup( ... "group1", ... [ ... OSError(1), ... SystemError(2), ... ExceptionGroup( ... "group2", ... [ ... OSError(3), ......
trusted_official_docs
CPython Docs
clause extracts from the group exceptions of a certain type while letting all other exceptions propagate to other clauses and eventually to be reraised. :: >>> def f(): ... raise ExceptionGroup( ... "group1", ... [ ... OSError(1), ... SystemError(2), ... ExceptionGroup( ... "group2", ... [ ... OSError(3), ......
clause extracts from the group exceptions of a certain type while letting all other exceptions propagate to other clauses and eventually to be reraised. :: >>> def f(): ... raise ExceptionGroup( ... "group1", ... [ ... OSError(1), ... SystemError(2), ... ExceptionGroup( ... "group2", ... [ ... OSError(3), ......
python, official-docs, cpython, P0
Local_Trusted_Corpus
05004a90-1105-451b-86ed-92881e7c2094
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,092
supabase-export-v2
ccb53d093e3ddc69
for line in open("myfile.txt"): print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. This is not an issue in simple scripts, but can be a problem for larger applications. The :keyword:`with` statement allow...
trusted_official_docs
CPython Docs
for line in open("myfile.txt"): print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. This is not an issue in simple scripts, but can be a problem for larger applications. The :keyword:`with` statement allow...
for line in open("myfile.txt"): print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. This is not an issue in simple scripts, but can be a problem for larger applications. The :keyword:`with` statement allow...
python, official-docs, cpython, P0
Local_Trusted_Corpus
07c11179-09bd-450b-b1d0-82a8e4fc91c0
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,021
supabase-export-v2
5cdba0aae7868f19
to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); note that a user-generated interruption is signalled by raising the :exc:`KeyboardInterrupt` exception. :: >>> while True: ... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("...
trusted_official_docs
CPython Docs
to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); note that a user-generated interruption is signalled by raising the :exc:`KeyboardInterrupt` exception. :: >>> while True: ... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("...
to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); note that a user-generated interruption is signalled by raising the :exc:`KeyboardInterrupt` exception. :: >>> while True: ... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("...
python, official-docs, cpython, P0
Local_Trusted_Corpus
08196c30-0491-4226-a9d4-aa6789613847
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,020
supabase-export-v2
9bdadea74db66631
Handling Exceptions =================== It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); ...
trusted_official_docs
CPython Docs
Handling Exceptions =================== It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); ...
Handling Exceptions =================== It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using :kbd:`Control-C` or whatever the operating system supports); ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
0881449e-54dd-490c-a14c-a7204a7a3c3a
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,036
supabase-export-v2
8f25217975a14b71
inst.args # unpack args ... print('x =', x) ... print('y =', y) ... <class 'Exception'> ('spam', 'eggs') ('spam', 'eggs') x = spam y = eggs The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions.
trusted_official_docs
CPython Docs
inst.args # unpack args ... print('x =', x) ... print('y =', y) ... <class 'Exception'> ('spam', 'eggs') ('spam', 'eggs') x = spam y = eggs The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions.
inst.args # unpack args ... print('x =', x) ... print('y =', y) ... <class 'Exception'> ('spam', 'eggs') ('spam', 'eggs') x = spam y = eggs The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions.
python, official-docs, cpython, P0
Local_Trusted_Corpus
09e4f0cf-e091-4ff2-9868-10df98da5dc3
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,085
supabase-export-v2
f6edc9063ff7aa70
A more complicated example:: >>> def divide(x, y): ... try: ... result = x / y ... except ZeroDivisionError: ... print("division by zero!") ... else: ... print("result is", result) ... finally: ... print("executing finally clause") ... >>> divide(2, 1) result is 2.0 executing finally clause >>> divide(2, 0)...
trusted_official_docs
CPython Docs
A more complicated example:: >>> def divide(x, y): ... try: ... result = x / y ... except ZeroDivisionError: ... print("division by zero!") ... else: ... print("result is", result) ... finally: ... print("executing finally clause") ... >>> divide(2, 1) result is 2.0 executing finally clause >>> divide(2, 0)...
A more complicated example:: >>> def divide(x, y): ... try: ... result = x / y ... except ZeroDivisionError: ... print("division by zero!") ... else: ... print("result is", result) ... finally: ... print("executing finally clause") ... >>> divide(2, 1) result is 2.0 executing finally clause >>> divide(2, 0)...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1066e95d-8e2a-4f4a-99b8-e43f8e233db0
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,060
supabase-export-v2
6a33f03a0c901c79
To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`from<raise>` clause:: # exc must be exception instance or None. raise RuntimeError from exc
trusted_official_docs
CPython Docs
To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`from<raise>` clause:: # exc must be exception instance or None. raise RuntimeError from exc
To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`from<raise>` clause:: # exc must be exception instance or None. raise RuntimeError from exc
python, official-docs, cpython, P0
Local_Trusted_Corpus
108b9da0-29b7-43c5-810c-1e9cb6b86c5b
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,108
supabase-export-v2
125933e68284fca5
and adds it to the exception's notes list. The standard traceback rendering includes all notes, in the order they were added, after the exception. :: >>> try: ... raise TypeError('bad type') ... except Exception as e: ... e.add_note('Add some information') ... e.add_note('Add some more information') ... raise ......
trusted_official_docs
CPython Docs
and adds it to the exception's notes list. The standard traceback rendering includes all notes, in the order they were added, after the exception. :: >>> try: ... raise TypeError('bad type') ... except Exception as e: ... e.add_note('Add some information') ... e.add_note('Add some more information') ... raise ......
and adds it to the exception's notes list. The standard traceback rendering includes all notes, in the order they were added, after the exception. :: >>> try: ... raise TypeError('bad type') ... except Exception as e: ... e.add_note('Add some information') ... e.add_note('Add some more information') ... raise ......
python, official-docs, cpython, P0
Local_Trusted_Corpus
10cbd30f-ef3d-4c33-a91e-a4e3f54fb592
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,039
supabase-export-v2
8de06deaa1328f8f
to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on. The most common pattern for handling :exc:`Exception` is to print or log the exception and then re-raise it (allowing a caller to handle the exception as well)::
trusted_official_docs
CPython Docs
to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on. The most common pattern for handling :exc:`Exception` is to print or log the exception and then re-raise it (allowing a caller to handle the exception as well)::
to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on. The most common pattern for handling :exc:`Exception` is to print or log the exception and then re-raise it (allowing a caller to handle the exception as well)::
python, official-docs, cpython, P0
Local_Trusted_Corpus
15df472e-c756-4933-ac75-d2eef77be83d
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,097
supabase-export-v2
a201c06ad7472991
Raising and Handling Multiple Unrelated Exceptions ================================================== There are situations where it is necessary to report several exceptions that have occurred. This is often the case in concurrency frameworks, when several tasks may have failed in parallel, but there are also other use...
trusted_official_docs
CPython Docs
Raising and Handling Multiple Unrelated Exceptions ================================================== There are situations where it is necessary to report several exceptions that have occurred. This is often the case in concurrency frameworks, when several tasks may have failed in parallel, but there are also other use...
Raising and Handling Multiple Unrelated Exceptions ================================================== There are situations where it is necessary to report several exceptions that have occurred. This is often the case in concurrency frameworks, when several tasks may have failed in parallel, but there are also other use...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1f3f7859-fada-40ab-96ec-7ce23a87795a
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,035
supabase-export-v2
dd9ea974e39c5579
has an ``args`` attribute that stores the arguments. For convenience, builtin exception types define :meth:`~object.__str__` to print all the arguments without explicitly accessing ``.args``. :: >>> try: ... raise Exception('spam', 'eggs') ... except Exception as inst: ... print(type(inst)) # the exception type ......
trusted_official_docs
CPython Docs
has an ``args`` attribute that stores the arguments. For convenience, builtin exception types define :meth:`~object.__str__` to print all the arguments without explicitly accessing ``.args``. :: >>> try: ... raise Exception('spam', 'eggs') ... except Exception as inst: ... print(type(inst)) # the exception type ......
has an ``args`` attribute that stores the arguments. For convenience, builtin exception types define :meth:`~object.__str__` to print all the arguments without explicitly accessing ``.args``. :: >>> try: ... raise Exception('spam', 'eggs') ... except Exception as inst: ... print(type(inst)) # the exception type ......
python, official-docs, cpython, P0
Local_Trusted_Corpus
2006e08d-c047-497a-893a-d0bc44d8fa90
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,044
supabase-export-v2
b48bde6ad283cf9b
for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close() The use of the :keyword:`!else` clause is better than adding additional code to the :keyword:`try` clause because it avoids accidentally catching an exception that wa...
trusted_official_docs
CPython Docs
for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close() The use of the :keyword:`!else` clause is better than adding additional code to the :keyword:`try` clause because it avoids accidentally catching an exception that wa...
for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close() The use of the :keyword:`!else` clause is better than adding additional code to the :keyword:`try` clause because it avoids accidentally catching an exception that wa...
python, official-docs, cpython, P0
Local_Trusted_Corpus
211d53bc-b9d9-4221-9fa3-f007fdd81167
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,009
supabase-export-v2
4baf037119631afd
>>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax The parser repeats the offending line and displays little arrows pointing at the place where the error was detected. Note that this is not always the place that needs to be fixed. In the example,...
trusted_official_docs
CPython Docs
>>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax The parser repeats the offending line and displays little arrows pointing at the place where the error was detected. Note that this is not always the place that needs to be fixed. In the example,...
>>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax The parser repeats the offending line and displays little arrows pointing at the place where the error was detected. Note that this is not always the place that needs to be fixed. In the example,...
python, official-docs, cpython, P0
Local_Trusted_Corpus
27eeda0f-135b-49dc-b548-95f24c4b7ec2
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,022
supabase-export-v2
86456bb0da047748
... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("Oops! That was no valid number. Try again...") ... The :keyword:`try` statement works as follows.
trusted_official_docs
CPython Docs
... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("Oops! That was no valid number. Try again...") ... The :keyword:`try` statement works as follows.
... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("Oops! That was no valid number. Try again...") ... The :keyword:`try` statement works as follows.
python, official-docs, cpython, P0
Local_Trusted_Corpus
2ab9d237-5bd5-4617-b919-be46ec38a15c
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,080
supabase-export-v2
f75e05a69fdd451e
statement, exceptions are not re-raised. This can be confusing and is therefore discouraged. From version 3.14 the compiler emits a :exc:`SyntaxWarning` for it (see :pep:`765`). * If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` c...
trusted_official_docs
CPython Docs
statement, exceptions are not re-raised. This can be confusing and is therefore discouraged. From version 3.14 the compiler emits a :exc:`SyntaxWarning` for it (see :pep:`765`). * If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` c...
statement, exceptions are not re-raised. This can be confusing and is therefore discouraged. From version 3.14 the compiler emits a :exc:`SyntaxWarning` for it (see :pep:`765`). * If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2de84028-7067-4b70-b5aa-bcfbeec3afda
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,012
supabase-export-v2
1c4986ece117ce83
Exceptions ========== Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called *exceptions* and are not unconditionally fatal: you will soon learn how to handle them in Python programs. Most exceptions are not ha...
trusted_official_docs
CPython Docs
Exceptions ========== Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called *exceptions* and are not unconditionally fatal: you will soon learn how to handle them in Python programs. Most exceptions are not ha...
Exceptions ========== Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called *exceptions* and are not unconditionally fatal: you will soon learn how to handle them in Python programs. Most exceptions are not ha...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2fe023fe-9d36-4998-abdf-7fb196c2e248
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,063
supabase-export-v2
626508c31cc3d12f
exception: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError('Failed to open database') from exc RuntimeError: Failed to open database It also allows disabling automatic exception chaining using the ``from None`` idiom::
trusted_official_docs
CPython Docs
exception: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError('Failed to open database') from exc RuntimeError: Failed to open database It also allows disabling automatic exception chaining using the ``from None`` idiom::
exception: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError('Failed to open database') from exc RuntimeError: Failed to open database It also allows disabling automatic exception chaining using the ``from None`` idiom::
python, official-docs, cpython, P0
Local_Trusted_Corpus
3a6cec5b-f667-49d0-8e45-abd02d25d068
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,069
supabase-export-v2
874a98af1dfb431b
creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly. Exception classes can be defined which do anything any other class can do, but are usually kept simple, often only offering a numb...
trusted_official_docs
CPython Docs
creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly. Exception classes can be defined which do anything any other class can do, but are usually kept simple, often only offering a numb...
creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly. Exception classes can be defined which do anything any other class can do, but are usually kept simple, often only offering a numb...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3cabf63d-ad99-4761-9a96-21ac1d614a91
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,099
supabase-export-v2
f73f3881cc7c27f3
of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any other exception. :: >>> def f(): ... excs = [OSError('error 1'), SystemError('error 2')] ... raise ExceptionGroup('there were problems', excs) ... >>> f() + Exception Group Traceback (most recent call...
trusted_official_docs
CPython Docs
of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any other exception. :: >>> def f(): ... excs = [OSError('error 1'), SystemError('error 2')] ... raise ExceptionGroup('there were problems', excs) ... >>> f() + Exception Group Traceback (most recent call...
of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any other exception. :: >>> def f(): ... excs = [OSError('error 1'), SystemError('error 2')] ... raise ExceptionGroup('there were problems', excs) ... >>> f() + Exception Group Traceback (most recent call...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3d9b74a4-fbe6-485a-a578-200d3b6276ce
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,109
supabase-export-v2
96fc735045ec2c7a
Traceback (most recent call last): File "<stdin>", line 2, in <module> raise TypeError('bad type') TypeError: bad type Add some information Add some more information >>> For example, when collecting exceptions into an exception group, we may want to add context information for the individual errors. In the following ea...
trusted_official_docs
CPython Docs
Traceback (most recent call last): File "<stdin>", line 2, in <module> raise TypeError('bad type') TypeError: bad type Add some information Add some more information >>> For example, when collecting exceptions into an exception group, we may want to add context information for the individual errors. In the following ea...
Traceback (most recent call last): File "<stdin>", line 2, in <module> raise TypeError('bad type') TypeError: bad type Add some information Add some more information >>> For example, when collecting exceptions into an exception group, we may want to add context information for the individual errors. In the following ea...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3f79a410-2770-47c5-93ad-b3cdc79b057f
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,107
supabase-export-v2
4495303662e5c58e
Enriching Exceptions with Notes =============================== When an exception is created in order to be raised, it is usually initialized with information that describes the error that has occurred. There are cases where it is useful to add information after the exception was caught. For this purpose, exceptions ha...
trusted_official_docs
CPython Docs
Enriching Exceptions with Notes =============================== When an exception is created in order to be raised, it is usually initialized with information that describes the error that has occurred. There are cases where it is useful to add information after the exception was caught. For this purpose, exceptions ha...
Enriching Exceptions with Notes =============================== When an exception is created in order to be raised, it is usually initialized with information that describes the error that has occurred. There are cases where it is useful to add information after the exception was caught. For this purpose, exceptions ha...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4bbde807-0d09-453f-a268-5797a22cc46c
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,032
supabase-export-v2
1c8e4fd4ececc3b4
for cls in [B, C, D]: try: raise cls() except D: print("D") except C: print("C") except B: print("B") Note that if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered.
trusted_official_docs
CPython Docs
for cls in [B, C, D]: try: raise cls() except D: print("D") except C: print("C") except B: print("B") Note that if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered.
for cls in [B, C, D]: try: raise cls() except D: print("D") except C: print("C") except B: print("B") Note that if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered.
python, official-docs, cpython, P0
Local_Trusted_Corpus
4c8e5fc9-a3c9-4c0f-a4a4-623e4e40021f
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,052
supabase-export-v2
20851af3320188a9
as :exc:`Exception` or one of its subclasses). If an exception class is passed, it will be implicitly instantiated by calling its constructor with no arguments:: raise ValueError # shorthand for 'raise ValueError()'
trusted_official_docs
CPython Docs
as :exc:`Exception` or one of its subclasses). If an exception class is passed, it will be implicitly instantiated by calling its constructor with no arguments:: raise ValueError # shorthand for 'raise ValueError()'
as :exc:`Exception` or one of its subclasses). If an exception class is passed, it will be implicitly instantiated by calling its constructor with no arguments:: raise ValueError # shorthand for 'raise ValueError()'
python, official-docs, cpython, P0
Local_Trusted_Corpus
50903902-5a6f-4e6f-abfd-4c3ce72fbc93
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,065
supabase-export-v2
ebd6aa48b56f9eaf
... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError For more information about chaining mechanics, see :ref:`bltin-exceptions`.
trusted_official_docs
CPython Docs
... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError For more information about chaining mechanics, see :ref:`bltin-exceptions`.
... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError For more information about chaining mechanics, see :ref:`bltin-exceptions`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
52c76cc8-2ab1-442a-b84c-a2e09f6bd4b3
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,014
supabase-export-v2
c25267a224012d12
2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str The last line of the error message indicates what happened. Exceptions come in different types, and the type is printed as part of the message: the types in the example are :ex...
trusted_official_docs
CPython Docs
2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str The last line of the error message indicates what happened. Exceptions come in different types, and the type is printed as part of the message: the types in the example are :ex...
2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str The last line of the error message indicates what happened. Exceptions come in different types, and the type is printed as part of the message: the types in the example are :ex...
python, official-docs, cpython, P0
Local_Trusted_Corpus