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
91e13ac5-f222-4b4c-a7c5-b33082399065
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,232
supabase-export-v2
456493292eb998e5
of a name that captures the essence of the comment. 4. Convert the lambda to a def statement, using that name. 5. Remove the comment. I really like these rules, but you're free to disagree about whether this lambda-free style is better.
trusted_official_docs
CPython Docs
of a name that captures the essence of the comment. 4. Convert the lambda to a def statement, using that name. 5. Remove the comment. I really like these rules, but you're free to disagree about whether this lambda-free style is better.
of a name that captures the essence of the comment. 4. Convert the lambda to a def statement, using that name. 5. Remove the comment. I really like these rules, but you're free to disagree about whether this lambda-free style is better.
python, official-docs, cpython, P0
Local_Trusted_Corpus
93d86fae-395a-4ada-87af-206f91c58038
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,067
supabase-export-v2
b314ab47181cb453
simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values. You're doubtless familiar with how regular function calls work in Python or C. When you call a function, it gets a private namespace where its local variables are c...
trusted_official_docs
CPython Docs
simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values. You're doubtless familiar with how regular function calls work in Python or C. When you call a function, it gets a private namespace where its local variables are c...
simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values. You're doubtless familiar with how regular function calls work in Python or C. When you call a function, it gets a private namespace where its local variables are c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
94a3cfeb-fc50-488c-ba0c-f65185e40bbd
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,172
supabase-export-v2
2689d395677df7c3
If you don't supply a value for *r* the length of the iterable is used, meaning that all the elements are permuted. Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique::
trusted_official_docs
CPython Docs
If you don't supply a value for *r* the length of the iterable is used, meaning that all the elements are permuted. Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique::
If you don't supply a value for *r* the length of the iterable is used, meaning that all the elements are permuted. Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique::
python, official-docs, cpython, P0
Local_Trusted_Corpus
94ba3677-8868-4594-b5d8-9807a37224a8
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,012
supabase-export-v2
1c88ebcc3781db91
Composability ------------- As you work on a functional-style program, you'll write a number of functions with varying inputs and outputs. Some of these functions will be unavoidably specialized to a particular application, but others will be useful in a wide variety of programs. For example, a function that takes a di...
trusted_official_docs
CPython Docs
Composability ------------- As you work on a functional-style program, you'll write a number of functions with varying inputs and outputs. Some of these functions will be unavoidably specialized to a particular application, but others will be useful in a wide variety of programs. For example, a function that takes a di...
Composability ------------- As you work on a functional-style program, you'll write a number of functions with varying inputs and outputs. Some of these functions will be unavoidably specialized to a particular application, but others will be useful in a wide variety of programs. For example, a function that takes a di...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9548f6e3-fb4a-4718-8222-cf333d2c1d48
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,153
supabase-export-v2
8df32b5966a7e0c2
Another group of functions chooses a subset of an iterator's elements based on a predicate. :func:`itertools.filterfalse(predicate, iter) <itertools.filterfalse>` is the opposite of :func:`filter`, returning all elements for which the predicate returns false::
trusted_official_docs
CPython Docs
Another group of functions chooses a subset of an iterator's elements based on a predicate. :func:`itertools.filterfalse(predicate, iter) <itertools.filterfalse>` is the opposite of :func:`filter`, returning all elements for which the predicate returns false::
Another group of functions chooses a subset of an iterator's elements based on a predicate. :func:`itertools.filterfalse(predicate, iter) <itertools.filterfalse>` is the opposite of :func:`filter`, returning all elements for which the predicate returns false::
python, official-docs, cpython, P0
Local_Trusted_Corpus
95c4bc5b-8af6-48eb-a4ad-8ec4f4d75a37
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,168
supabase-export-v2
c5db4805c58bb753
4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5) The elements within each tuple remain in the same order as *iterable* returned them. For example, the number 1 is always before 2, 3, 4, or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=No...
trusted_official_docs
CPython Docs
4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5) The elements within each tuple remain in the same order as *iterable* returned them. For example, the number 1 is always before 2, 3, 4, or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=No...
4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5) The elements within each tuple remain in the same order as *iterable* returned them. For example, the number 1 is always before 2, 3, 4, or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=No...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9615e34d-bf6f-449a-b94f-13ab17bde000
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,083
supabase-export-v2
eebebe002691b7b2
Passing values into a generator ------------------------------- In Python 2.4 and earlier, generators only produced output. Once a generator's code was invoked to create an iterator, there was no way to pass any new information into the function when its execution is resumed. You could hack together this ability by mak...
trusted_official_docs
CPython Docs
Passing values into a generator ------------------------------- In Python 2.4 and earlier, generators only produced output. Once a generator's code was invoked to create an iterator, there was no way to pass any new information into the function when its execution is resumed. You could hack together this ability by mak...
Passing values into a generator ------------------------------- In Python 2.4 and earlier, generators only produced output. Once a generator's code was invoked to create an iterator, there was no way to pass any new information into the function when its execution is resumed. You could hack together this ability by mak...
python, official-docs, cpython, P0
Local_Trusted_Corpus
983f3a2f-e812-455f-8820-fe82713bfbd9
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,021
supabase-export-v2
d375ee0c4b4e0bcb
same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration >>> Python expects iterable objects in several different contexts, the most important being the :keyword:`for` statement. In the statement ``for X in Y``, Y must be an itera...
trusted_official_docs
CPython Docs
same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration >>> Python expects iterable objects in several different contexts, the most important being the :keyword:`for` statement. In the statement ``for X in Y``, Y must be an itera...
same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration >>> Python expects iterable objects in several different contexts, the most important being the :keyword:`for` statement. In the statement ``for X in Y``, Y must be an itera...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9862d685-0e48-414c-b62a-6149733d7bd4
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,020
supabase-export-v2
f676fb1b45e718a4
You can experiment with the iteration interface manually: >>> L = [1, 2, 3] >>> it = iter(L) >>> it #doctest: +ELLIPSIS <...iterator object at ...> >>> it.__next__() # same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIt...
trusted_official_docs
CPython Docs
You can experiment with the iteration interface manually: >>> L = [1, 2, 3] >>> it = iter(L) >>> it #doctest: +ELLIPSIS <...iterator object at ...> >>> it.__next__() # same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIt...
You can experiment with the iteration interface manually: >>> L = [1, 2, 3] >>> it = iter(L) >>> it #doctest: +ELLIPSIS <...iterator object at ...> >>> it.__next__() # same as next(it) 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIt...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9b222874-5b2f-47d1-8f2b-a9e3ca5c861e
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,220
supabase-export-v2
0e74160b205fe778
Which alternative is preferable? That's a style question; my usual course is to avoid using ``lambda``. One reason for my preference is that ``lambda`` is quite limited in the functions it can define. The result has to be computable as a single expression, which means you can't have multiway ``if... elif... else`` comp...
trusted_official_docs
CPython Docs
Which alternative is preferable? That's a style question; my usual course is to avoid using ``lambda``. One reason for my preference is that ``lambda`` is quite limited in the functions it can define. The result has to be computable as a single expression, which means you can't have multiway ``if... elif... else`` comp...
Which alternative is preferable? That's a style question; my usual course is to avoid using ``lambda``. One reason for my preference is that ``lambda`` is quite limited in the functions it can define. The result has to be computable as a single expression, which means you can't have multiway ``if... elif... else`` comp...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9b25c659-7e50-43b1-b659-49e3248922ef
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,038
supabase-export-v2
0649a403575264a2
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')] >>> dict(iter(L)) {'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} Files also support iteration by calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a fil...
trusted_official_docs
CPython Docs
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')] >>> dict(iter(L)) {'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} Files also support iteration by calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a fil...
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')] >>> dict(iter(L)) {'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} Files also support iteration by calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a fil...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9c46ea7a-e89e-405e-a4f5-1ee6e6598116
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,100
supabase-export-v2
3b6837546755bf5f
The cumulative effect of these changes is to turn generators from one-way producers of information into both producers and consumers. Generators also become **coroutines**, a more generalized form of subroutines. Subroutines are entered at one point and exited at another point (the top of the function, and a ``return``...
trusted_official_docs
CPython Docs
The cumulative effect of these changes is to turn generators from one-way producers of information into both producers and consumers. Generators also become **coroutines**, a more generalized form of subroutines. Subroutines are entered at one point and exited at another point (the top of the function, and a ``return``...
The cumulative effect of these changes is to turn generators from one-way producers of information into both producers and consumers. Generators also become **coroutines**, a more generalized form of subroutines. Subroutines are entered at one point and exited at another point (the top of the function, and a ``return``...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9d3cd4b3-6190-4b94-be66-c39af1a63324
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,231
supabase-export-v2
8cdf0f33205110b5
Fredrik Lundh once suggested the following set of rules for refactoring uses of ``lambda``: 1. Write a lambda function. 2. Write a comment explaining what the heck that lambda does. 3. Study the comment for a while, and think of a name that captures the essence of the comment. 4. Convert the lambda to a def statement,...
trusted_official_docs
CPython Docs
Fredrik Lundh once suggested the following set of rules for refactoring uses of ``lambda``: 1. Write a lambda function. 2. Write a comment explaining what the heck that lambda does. 3. Study the comment for a while, and think of a name that captures the essence of the comment. 4. Convert the lambda to a def statement,...
Fredrik Lundh once suggested the following set of rules for refactoring uses of ``lambda``: 1. Write a lambda function. 2. Write a comment explaining what the heck that lambda does. 3. Study the comment for a while, and think of a name that captures the essence of the comment. 4. Convert the lambda to a def statement,...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9e246ab9-d104-4726-a1a7-ca18ef039a20
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,239
supabase-export-v2
17eaa47300d5753c
Version 0.21: Added more references suggested on the tutor mailing list. Version 0.30: Adds a section on the ``functional`` module written by Collin Winter; adds short section on the operator module; a few other edits.
trusted_official_docs
CPython Docs
Version 0.21: Added more references suggested on the tutor mailing list. Version 0.30: Adds a section on the ``functional`` module written by Collin Winter; adds short section on the operator module; a few other edits.
Version 0.21: Added more references suggested on the tutor mailing list. Version 0.30: Adds a section on the ``functional`` module written by Collin Winter; adds short section on the operator module; a few other edits.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9f133141-8e60-4f9f-88dd-20297b4ffe8b
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,077
supabase-export-v2
1030e56258f56494
0, and having the :meth:`~iterator.__next__` method increment ``self.count`` and return it. However, for a moderately complicated generator, writing a corresponding class can be much messier. The test suite included with Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting exam...
trusted_official_docs
CPython Docs
0, and having the :meth:`~iterator.__next__` method increment ``self.count`` and return it. However, for a moderately complicated generator, writing a corresponding class can be much messier. The test suite included with Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting exam...
0, and having the :meth:`~iterator.__next__` method increment ``self.count`` and return it. However, for a moderately complicated generator, writing a corresponding class can be much messier. The test suite included with Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting exam...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9f5e1aea-e5bb-4a9b-b8e3-94bc55edcdc5
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,028
supabase-export-v2
38d13cf89d1800a6
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> a, b, c = iterator >>> a, b, c (1, 2, 3) Built-in functions such as :func:`max` and :func:`min` can take a single iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X...
trusted_official_docs
CPython Docs
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> a, b, c = iterator >>> a, b, c (1, 2, 3) Built-in functions such as :func:`max` and :func:`min` can take a single iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X...
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> a, b, c = iterator >>> a, b, c (1, 2, 3) Built-in functions such as :func:`max` and :func:`min` can take a single iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a00401b7-f05f-47d3-91b3-d5cefe9d00f9
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,234
supabase-export-v2
dcff25e4eeceee69
Revision History and Acknowledgements ===================================== The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Ju...
trusted_official_docs
CPython Docs
Revision History and Acknowledgements ===================================== The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Ju...
Revision History and Acknowledgements ===================================== The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Ju...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a0bd9801-bf42-4c4a-bd5a-2635ffb0558d
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
56,990
supabase-export-v2
09b4518dbcf73c00
data set you want to retrieve, and the SQL engine decides whether to scan tables or use indexes, which subclauses should be performed first, etc. * **Object-oriented** programs manipulate collections of objects. Objects have internal state and support methods that query or modify this internal state in some way. Smal...
trusted_official_docs
CPython Docs
data set you want to retrieve, and the SQL engine decides whether to scan tables or use indexes, which subclauses should be performed first, etc. * **Object-oriented** programs manipulate collections of objects. Objects have internal state and support methods that query or modify this internal state in some way. Smal...
data set you want to retrieve, and the SQL engine decides whether to scan tables or use indexes, which subclauses should be performed first, etc. * **Object-oriented** programs manipulate collections of objects. Objects have internal state and support methods that query or modify this internal state in some way. Smal...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a1326666-5466-4c23-aecc-a81b776f27e5
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,140
supabase-export-v2
0ed815b1201bc888
the elements of the first iterator, then all the elements of the second, and so on, until all of the iterables have been exhausted. :: itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3
trusted_official_docs
CPython Docs
the elements of the first iterator, then all the elements of the second, and so on, until all of the iterables have been exhausted. :: itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3
the elements of the first iterator, then all the elements of the second, and so on, until all of the iterables have been exhausted. :: itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3
python, official-docs, cpython, P0
Local_Trusted_Corpus
a17f11da-3539-41fa-8077-0ece081a635d
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,076
supabase-export-v2
c0708e9488bd5196
method. Once this happens, or the bottom of the function is reached, the procession of values ends and the generator cannot yield any further values. You could achieve the effect of generators manually by writing your own class and storing all the local variables of the generator as instance variables. For example, ret...
trusted_official_docs
CPython Docs
method. Once this happens, or the bottom of the function is reached, the procession of values ends and the generator cannot yield any further values. You could achieve the effect of generators manually by writing your own class and storing all the local variables of the generator as instance variables. For example, ret...
method. Once this happens, or the bottom of the function is reached, the procession of values ends and the generator cannot yield any further values. You could achieve the effect of generators manually by writing your own class and storing all the local variables of the generator as instance variables. For example, ret...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a578c3e1-a176-40fa-a1a8-b7715266d799
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,026
supabase-export-v2
4dfc6b81a0b05101
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> t = tuple(iterator) >>> t (1, 2, 3) Sequence unpacking also supports iterators: if you know an iterator will return N elements, you can unpack them into an N-tuple:
trusted_official_docs
CPython Docs
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> t = tuple(iterator) >>> t (1, 2, 3) Sequence unpacking also supports iterators: if you know an iterator will return N elements, you can unpack them into an N-tuple:
>>> L = [1, 2, 3] >>> iterator = iter(L) >>> t = tuple(iterator) >>> t (1, 2, 3) Sequence unpacking also supports iterators: if you know an iterator will return N elements, you can unpack them into an N-tuple:
python, official-docs, cpython, P0
Local_Trusted_Corpus
a70711b7-6fbc-447f-86fe-357407c3ad35
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,007
supabase-export-v2
7115a50ae9f3c644
that does one thing than a large function that performs a complicated transformation. Small functions are also easier to read and to check for errors. Ease of debugging and testing -----------------------------
trusted_official_docs
CPython Docs
that does one thing than a large function that performs a complicated transformation. Small functions are also easier to read and to check for errors. Ease of debugging and testing -----------------------------
that does one thing than a large function that performs a complicated transformation. Small functions are also easier to read and to check for errors. Ease of debugging and testing -----------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
a7bf3a47-ae9d-4ed1-97bb-57aac9dc8f8a
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,187
supabase-export-v2
c96fb62c2b1da56f
The functools module ==================== The :mod:`functools` module contains some higher-order functions. A **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
trusted_official_docs
CPython Docs
The functools module ==================== The :mod:`functools` module contains some higher-order functions. A **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
The functools module ==================== The :mod:`functools` module contains some higher-order functions. A **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
python, official-docs, cpython, P0
Local_Trusted_Corpus
af778836-1a26-4bdb-a2aa-bc94a4b19f38
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,235
supabase-export-v2
6194fb3ebe98b8f2
various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Jussi Salmela, Collin Winter, Blake Winton. Version 0.1: posted June 30 2006.
trusted_official_docs
CPython Docs
various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Jussi Salmela, Collin Winter, Blake Winton. Version 0.1: posted June 30 2006.
various drafts of this article: Ian Bicking, Nick Coghlan, Nick Efford, Raymond Hettinger, Jim Jewett, Mike Krell, Leandro Lameiro, Jussi Salmela, Collin Winter, Blake Winton. Version 0.1: posted June 30 2006.
python, official-docs, cpython, P0
Local_Trusted_Corpus
b109f266-6307-428a-84e2-930a95f32ec8
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,114
supabase-export-v2
d2a18bffe088aaa3
:func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. :: >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
trusted_official_docs
CPython Docs
:func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. :: >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
:func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. :: >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
python, official-docs, cpython, P0
Local_Trusted_Corpus
b198e340-e1ff-4d30-a291-48a97f5d4049
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,029
supabase-export-v2
0fa96fd708ab9127
infinite; :func:`max`, :func:`min` will never return, and if the element X never appears in the stream, the ``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects ca...
trusted_official_docs
CPython Docs
infinite; :func:`max`, :func:`min` will never return, and if the element X never appears in the stream, the ``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects ca...
infinite; :func:`max`, :func:`min` will never return, and if the element X never appears in the stream, the ``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects ca...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b1d95a67-4f8d-4e40-9260-9ef3ad28d74a
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,141
supabase-export-v2
46ec6347738d2ab8
itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3 :func:`itertools.islice(iter, [start], stop, [step]) <itertools.islice>` returns a stream that's a slice of the iterator. With a single *stop* argument, it will return the first *stop* elements. If you supply a starting index, you'll get *stop-start* eleme...
trusted_official_docs
CPython Docs
itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3 :func:`itertools.islice(iter, [start], stop, [step]) <itertools.islice>` returns a stream that's a slice of the iterator. With a single *stop* argument, it will return the first *stop* elements. If you supply a starting index, you'll get *stop-start* eleme...
itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3 :func:`itertools.islice(iter, [start], stop, [step]) <itertools.islice>` returns a stream that's a slice of the iterator. With a single *stop* argument, it will return the first *stop* elements. If you supply a starting index, you'll get *stop-start* eleme...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b4950295-f26d-4b19-9ebb-a6abaa61445c
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,212
supabase-export-v2
ea08008f15a6695f
If there's a Python built-in or a module function that's suitable, you don't need to define a new function at all:: stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list)
trusted_official_docs
CPython Docs
If there's a Python built-in or a module function that's suitable, you don't need to define a new function at all:: stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list)
If there's a Python built-in or a module function that's suitable, you don't need to define a new function at all:: stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list)
python, official-docs, cpython, P0
Local_Trusted_Corpus
b4dd4753-ce5d-4452-8156-599f57023156
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,032
supabase-export-v2
7b298080c81db5bd
We've already seen how lists and tuples support iterators. In fact, any Python sequence type, such as strings, will automatically support creation of an iterator. Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys::
trusted_official_docs
CPython Docs
We've already seen how lists and tuples support iterators. In fact, any Python sequence type, such as strings, will automatically support creation of an iterator. Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys::
We've already seen how lists and tuples support iterators. In fact, any Python sequence type, such as strings, will automatically support creation of an iterator. Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys::
python, official-docs, cpython, P0
Local_Trusted_Corpus
b71f65bd-42ce-49ff-bece-9b9f689bf2f5
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,133
supabase-export-v2
36174d191f904211
Creating new iterators ---------------------- :func:`itertools.count(start, step) <itertools.count>` returns an infinite stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
trusted_official_docs
CPython Docs
Creating new iterators ---------------------- :func:`itertools.count(start, step) <itertools.count>` returns an infinite stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
Creating new iterators ---------------------- :func:`itertools.count(start, step) <itertools.count>` returns an infinite stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
python, official-docs, cpython, P0
Local_Trusted_Corpus
b796ecbe-4b03-412b-aa2b-dbb9b0e9e7ef
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,072
supabase-export-v2
ae16c07154f8b2c5
generator's state of execution is suspended and local variables are preserved. On the next call to the generator's :meth:`~generator.__next__` method, the function will resume executing. Here's a sample usage of the ``generate_ints()`` generator:
trusted_official_docs
CPython Docs
generator's state of execution is suspended and local variables are preserved. On the next call to the generator's :meth:`~generator.__next__` method, the function will resume executing. Here's a sample usage of the ``generate_ints()`` generator:
generator's state of execution is suspended and local variables are preserved. On the next call to the generator's :meth:`~generator.__next__` method, the function will resume executing. Here's a sample usage of the ``generate_ints()`` generator:
python, official-docs, cpython, P0
Local_Trusted_Corpus
bb0a848e-3651-4644-a465-aecefbc50aab
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,155
supabase-export-v2
bd4e637c84333381
itertools.filterfalse(is_even, itertools.count()) => 1, 3, 5, 7, 9, 11, 13, 15, ... :func:`itertools.takewhile(predicate, iter) <itertools.takewhile>` returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. ::
trusted_official_docs
CPython Docs
itertools.filterfalse(is_even, itertools.count()) => 1, 3, 5, 7, 9, 11, 13, 15, ... :func:`itertools.takewhile(predicate, iter) <itertools.takewhile>` returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. ::
itertools.filterfalse(is_even, itertools.count()) => 1, 3, 5, 7, 9, 11, 13, 15, ... :func:`itertools.takewhile(predicate, iter) <itertools.takewhile>` returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
bcf7ef8c-0387-4a2b-a48e-badfd901e71a
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,120
supabase-export-v2
99066646d3293422
(For a more detailed discussion of sorting, see the :ref:`sortinghowto`.) The :func:`any(iter) <any>` and :func:`all(iter) <all>` built-ins look at the truth values of an iterable's contents. :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elem...
trusted_official_docs
CPython Docs
(For a more detailed discussion of sorting, see the :ref:`sortinghowto`.) The :func:`any(iter) <any>` and :func:`all(iter) <all>` built-ins look at the truth values of an iterable's contents. :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elem...
(For a more detailed discussion of sorting, see the :ref:`sortinghowto`.) The :func:`any(iter) <any>` and :func:`all(iter) <all>` built-ins look at the truth values of an iterable's contents. :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elem...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bcf8110d-63ce-4feb-bd99-0ae52539f95c
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,130
supabase-export-v2
262654bf8cf2747b
a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples. The module's functions fall into a few broad classes:
trusted_official_docs
CPython Docs
a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples. The module's functions fall into a few broad classes:
a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples. The module's functions fall into a few broad classes:
python, official-docs, cpython, P0
Local_Trusted_Corpus
bdc9774b-86c1-4329-b88c-d5ff4ee79f65
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,258
supabase-export-v2
8a4623f7bd4c6928
Handy little function for printing part of an iterator -- used while writing this document. import itertools def print_iter(it): slice = itertools.islice(it, 10) for elem in slice[:-1]: sys.stdout.write(str(elem)) sys.stdout.write(', ') print(elem[-1])
trusted_official_docs
CPython Docs
Handy little function for printing part of an iterator -- used while writing this document. import itertools def print_iter(it): slice = itertools.islice(it, 10) for elem in slice[:-1]: sys.stdout.write(str(elem)) sys.stdout.write(', ') print(elem[-1])
Handy little function for printing part of an iterator -- used while writing this document. import itertools def print_iter(it): slice = itertools.islice(it, 10) for elem in slice[:-1]: sys.stdout.write(str(elem)) sys.stdout.write(', ') print(elem[-1])
python, official-docs, cpython, P0
Local_Trusted_Corpus
be7b5c59-6509-4e23-93d1-f42b4cbe8a8c
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,122
supabase-export-v2
c6ca478117e17a88
>>> any([0, 0, 0]) False >>> any([1, 1, 1]) True >>> all([0, 1, 0]) False >>> all([0, 0, 0]) False >>> all([1, 1, 1]) True :func:`zip(iterA, iterB, ...) <zip>` takes one element from each iterable and returns them in a tuple::
trusted_official_docs
CPython Docs
>>> any([0, 0, 0]) False >>> any([1, 1, 1]) True >>> all([0, 1, 0]) False >>> all([0, 0, 0]) False >>> all([1, 1, 1]) True :func:`zip(iterA, iterB, ...) <zip>` takes one element from each iterable and returns them in a tuple::
>>> any([0, 0, 0]) False >>> any([1, 1, 1]) True >>> all([0, 1, 0]) False >>> all([0, 0, 0]) False >>> all([1, 1, 1]) True :func:`zip(iterA, iterB, ...) <zip>` takes one element from each iterable and returns them in a tuple::
python, official-docs, cpython, P0
Local_Trusted_Corpus
c3a8bd42-2539-444a-b77e-ea6d4919c3c1
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,104
supabase-export-v2
27ceaf84d8e9397f
Two of Python's built-in functions, :func:`map` and :func:`filter` duplicate the features of generator expressions: :func:`map(f, iterA, iterB, ...) <map>` returns an iterator over the sequence ``f(iterA[0], iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.
trusted_official_docs
CPython Docs
Two of Python's built-in functions, :func:`map` and :func:`filter` duplicate the features of generator expressions: :func:`map(f, iterA, iterB, ...) <map>` returns an iterator over the sequence ``f(iterA[0], iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.
Two of Python's built-in functions, :func:`map` and :func:`filter` duplicate the features of generator expressions: :func:`map(f, iterA, iterB, ...) <map>` returns an iterator over the sequence ``f(iterA[0], iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
c4dbd959-6ae9-4572-a76a-e0066a9c0024
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,125
supabase-export-v2
9b812f1ff3ff2879
the input iterators before returning; instead tuples are constructed and returned only if they're requested. (The technical term for this behaviour is `lazy evaluation <https://en.wikipedia.org/wiki/Lazy_evaluation>`__.) This iterator is intended to be used with iterables that are all of the same length. If the iterabl...
trusted_official_docs
CPython Docs
the input iterators before returning; instead tuples are constructed and returned only if they're requested. (The technical term for this behaviour is `lazy evaluation <https://en.wikipedia.org/wiki/Lazy_evaluation>`__.) This iterator is intended to be used with iterables that are all of the same length. If the iterabl...
the input iterators before returning; instead tuples are constructed and returned only if they're requested. (The technical term for this behaviour is `lazy evaluation <https://en.wikipedia.org/wiki/Lazy_evaluation>`__.) This iterator is intended to be used with iterables that are all of the same length. If the iterabl...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c4dcaa2d-7c48-4a50-a43b-d262689398fe
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,088
supabase-export-v2
19d5000e51f48ae1
means you can write ``val = yield i`` but have to use parentheses when there's an operation, as in ``val = (yield i) + 12``.) Values are sent into a generator by calling its :meth:`send(value) <generator.send>` method. This method resumes the generator's code and the ``yield`` expression returns the specified value. If...
trusted_official_docs
CPython Docs
means you can write ``val = yield i`` but have to use parentheses when there's an operation, as in ``val = (yield i) + 12``.) Values are sent into a generator by calling its :meth:`send(value) <generator.send>` method. This method resumes the generator's code and the ``yield`` expression returns the specified value. If...
means you can write ``val = yield i`` but have to use parentheses when there's an operation, as in ``val = (yield i) + 12``.) Values are sent into a generator by calling its :meth:`send(value) <generator.send>` method. This method resumes the generator's code and the ``yield`` expression returns the specified value. If...
python, official-docs, cpython, P0
Local_Trusted_Corpus
cc4990a3-3a77-4ac8-b4cb-cdd98a3ed5a9
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,010
supabase-export-v2
17dd523dc56813c0
check that the data are correct. You can look at the intermediate inputs and outputs to quickly isolate the function that's responsible for a bug. Testing is easier because each function is a potential subject for a unit test. Functions don't depend on system state that needs to be replicated before running a test; ins...
trusted_official_docs
CPython Docs
check that the data are correct. You can look at the intermediate inputs and outputs to quickly isolate the function that's responsible for a bug. Testing is easier because each function is a potential subject for a unit test. Functions don't depend on system state that needs to be replicated before running a test; ins...
check that the data are correct. You can look at the intermediate inputs and outputs to quickly isolate the function that's responsible for a bug. Testing is easier because each function is a potential subject for a unit test. Functions don't depend on system state that needs to be replicated before running a test; ins...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ccc1b8b5-ff89-4729-b9bf-cc94d7ae50bd
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,221
supabase-export-v2
77bd2e4d99748ba7
too much in a ``lambda`` statement, you'll end up with an overly complicated expression that's hard to read. Quick, what's the following code doing? :: import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
trusted_official_docs
CPython Docs
too much in a ``lambda`` statement, you'll end up with an overly complicated expression that's hard to read. Quick, what's the following code doing? :: import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
too much in a ``lambda`` statement, you'll end up with an overly complicated expression that's hard to read. Quick, what's the following code doing? :: import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
python, official-docs, cpython, P0
Local_Trusted_Corpus
cda34743-77a8-467b-9af7-cf2b6db22543
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,202
supabase-export-v2
75d7951a869c3d49
func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each partial result:: itertools.accumulate([1, 2, 3, 4, 5]) => 1, 3, 6, 10, 15
trusted_official_docs
CPython Docs
func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each partial result:: itertools.accumulate([1, 2, 3, 4, 5]) => 1, 3, 6, 10, 15
func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each partial result:: itertools.accumulate([1, 2, 3, 4, 5]) => 1, 3, 6, 10, 15
python, official-docs, cpython, P0
Local_Trusted_Corpus
ce9b7b86-6a29-49f8-922c-1687c416a13c
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,119
supabase-export-v2
eae0c18fe966f3fc
>>> sorted(rand_list) #doctest: +SKIP [769, 2207, 6213, 6431, 7953, 8442, 9828, 9878] >>> sorted(rand_list, reverse=True) #doctest: +SKIP [9878, 9828, 8442, 7953, 6431, 6213, 2207, 769] (For a more detailed discussion of sorting, see the :ref:`sortinghowto`.)
trusted_official_docs
CPython Docs
>>> sorted(rand_list) #doctest: +SKIP [769, 2207, 6213, 6431, 7953, 8442, 9828, 9878] >>> sorted(rand_list, reverse=True) #doctest: +SKIP [9878, 9828, 8442, 7953, 6431, 6213, 2207, 769] (For a more detailed discussion of sorting, see the :ref:`sortinghowto`.)
>>> sorted(rand_list) #doctest: +SKIP [769, 2207, 6213, 6431, 7953, 8442, 9828, 9878] >>> sorted(rand_list, reverse=True) #doctest: +SKIP [9878, 9828, 8442, 7953, 6431, 6213, 2207, 769] (For a more detailed discussion of sorting, see the :ref:`sortinghowto`.)
python, official-docs, cpython, P0
Local_Trusted_Corpus
d044bdb3-b8e6-4166-a7e6-3f086ae383e0
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
56,994
supabase-export-v2
f4277c58f6f200fb
functional**. Avoiding side effects means not using data structures that get updated as a program runs; every function's output must only depend on its input. Some languages are very strict about purity and don't even have assignment statements such as ``a=3`` or ``c = a + b``, but it's difficult to avoid all side effe...
trusted_official_docs
CPython Docs
functional**. Avoiding side effects means not using data structures that get updated as a program runs; every function's output must only depend on its input. Some languages are very strict about purity and don't even have assignment statements such as ``a=3`` or ``c = a + b``, but it's difficult to avoid all side effe...
functional**. Avoiding side effects means not using data structures that get updated as a program runs; every function's output must only depend on its input. Some languages are very strict about purity and don't even have assignment statements such as ``a=3`` or ``c = a + b``, but it's difficult to avoid all side effe...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d4da2aae-140c-496e-8bfd-34b1438d04cd
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,086
supabase-export-v2
43825142a080b301
val = (yield i) I recommend that you **always** put parentheses around a ``yield`` expression when you're doing something with the returned value, as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
trusted_official_docs
CPython Docs
val = (yield i) I recommend that you **always** put parentheses around a ``yield`` expression when you're doing something with the returned value, as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
val = (yield i) I recommend that you **always** put parentheses around a ``yield`` expression when you're doing something with the returned value, as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
python, official-docs, cpython, P0
Local_Trusted_Corpus
d5450dd0-609b-43ab-bd55-116d1934684d
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,097
supabase-export-v2
863f28ee44233925
:meth:`throw(value) <generator.throw>` is used to raise an exception inside the generator; the exception is raised by the ``yield`` expression where the generator's execution is paused. * :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the generator to terminate the iteration. On receiving this exce...
trusted_official_docs
CPython Docs
:meth:`throw(value) <generator.throw>` is used to raise an exception inside the generator; the exception is raised by the ``yield`` expression where the generator's execution is paused. * :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the generator to terminate the iteration. On receiving this exce...
:meth:`throw(value) <generator.throw>` is used to raise an exception inside the generator; the exception is raised by the ``yield`` expression where the generator's execution is paused. * :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the generator to terminate the iteration. On receiving this exce...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d58051e7-7096-43fe-b45c-d97dbf712270
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,129
supabase-export-v2
e47bf64df1be9811
The itertools module ==================== The :mod:`itertools` module contains a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples.
trusted_official_docs
CPython Docs
The itertools module ==================== The :mod:`itertools` module contains a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples.
The itertools module ==================== The :mod:`itertools` module contains a number of commonly used iterators as well as functions for combining several iterators. This section will introduce the module's contents by showing small examples.
python, official-docs, cpython, P0
Local_Trusted_Corpus
d66c541d-66a6-477e-924a-0018619f9098
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,198
supabase-export-v2
fefc4c56594f6c38
>>> import functools, operator >>> functools.reduce(operator.add, [1, 2, 3, 4], 0) 10 >>> sum([1, 2, 3, 4]) 10 >>> sum([]) 0 For many uses of :func:`functools.reduce`, though, it can be clearer to just write the obvious :keyword:`for` loop::
trusted_official_docs
CPython Docs
>>> import functools, operator >>> functools.reduce(operator.add, [1, 2, 3, 4], 0) 10 >>> sum([1, 2, 3, 4]) 10 >>> sum([]) 0 For many uses of :func:`functools.reduce`, though, it can be clearer to just write the obvious :keyword:`for` loop::
>>> import functools, operator >>> functools.reduce(operator.add, [1, 2, 3, 4], 0) 10 >>> sum([1, 2, 3, 4]) 10 >>> sum([]) 0 For many uses of :func:`functools.reduce`, though, it can be clearer to just write the obvious :keyword:`for` loop::
python, official-docs, cpython, P0
Local_Trusted_Corpus
d7581482-308e-453b-99cc-df57cc3fac57
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,169
supabase-export-v2
8ec3a11a850c6435
or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=None) <itertools.permutations>`, removes this constraint on the order, returning all possible arrangements of length *r*:: itertools.permutations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 3), (2, 4), (2,...
trusted_official_docs
CPython Docs
or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=None) <itertools.permutations>`, removes this constraint on the order, returning all possible arrangements of length *r*:: itertools.permutations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 3), (2, 4), (2,...
or 5 in the examples above. A similar function, :func:`itertools.permutations(iterable, r=None) <itertools.permutations>`, removes this constraint on the order, returning all possible arrangements of length *r*:: itertools.permutations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 3), (2, 4), (2,...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d81390c7-38a8-45f1-a699-f83d143cb940
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,208
supabase-export-v2
cc8b4dac62870295
* Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object identity: ``is_()``, ``is_not()``. Consult the operator module's documentation for a complete list.
trusted_official_docs
CPython Docs
* Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object identity: ``is_()``, ``is_not()``. Consult the operator module's documentation for a complete list.
* Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object identity: ``is_()``, ``is_not()``. Consult the operator module's documentation for a complete list.
python, official-docs, cpython, P0
Local_Trusted_Corpus
dbcb2f8a-d2a0-4a2f-8ebc-e57345e24cb3
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,081
supabase-export-v2
c0234d96e57a9465
for x in inorder(t.right): yield x Two other examples in ``test_generators.py`` produce solutions for the N-Queens problem (placing N queens on an NxN chess board so that no queen threatens another) and the Knight's Tour (finding a route that takes a knight to every square of an NxN chessboard without visiting any squa...
trusted_official_docs
CPython Docs
for x in inorder(t.right): yield x Two other examples in ``test_generators.py`` produce solutions for the N-Queens problem (placing N queens on an NxN chess board so that no queen threatens another) and the Knight's Tour (finding a route that takes a knight to every square of an NxN chessboard without visiting any squa...
for x in inorder(t.right): yield x Two other examples in ``test_generators.py`` produce solutions for the N-Queens problem (placing N queens on an NxN chess board so that no queen threatens another) and the Knight's Tour (finding a route that takes a knight to every square of an NxN chessboard without visiting any squa...
python, official-docs, cpython, P0
Local_Trusted_Corpus
dd3f4ae2-3eb5-49fc-b77e-30c56ba2f025
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,194
supabase-export-v2
a5fcee30bbf6ee9d
server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket') :func:`functools.reduce(func, iter, [initial_value]) <functools.reduce>` cumulatively performs an operation on all the iterable's elements and, therefore, can't be applied to infinite iterables. *func* must be a function that ta...
trusted_official_docs
CPython Docs
server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket') :func:`functools.reduce(func, iter, [initial_value]) <functools.reduce>` cumulatively performs an operation on all the iterable's elements and, therefore, can't be applied to infinite iterables. *func* must be a function that ta...
server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket') :func:`functools.reduce(func, iter, [initial_value]) <functools.reduce>` cumulatively performs an operation on all the iterable's elements and, therefore, can't be applied to infinite iterables. *func* must be a function that ta...
python, official-docs, cpython, P0
Local_Trusted_Corpus
dd50e65b-52e3-4461-91e2-790290a08ed5
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,059
supabase-export-v2
22d5dd94a2fec52e
To put it another way, a list comprehension or generator expression is equivalent to the following Python code:: for expr1 in sequence1: if not (condition1): continue # Skip this element for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): co...
trusted_official_docs
CPython Docs
To put it another way, a list comprehension or generator expression is equivalent to the following Python code:: for expr1 in sequence1: if not (condition1): continue # Skip this element for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): co...
To put it another way, a list comprehension or generator expression is equivalent to the following Python code:: for expr1 in sequence1: if not (condition1): continue # Skip this element for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): co...
python, official-docs, cpython, P0
Local_Trusted_Corpus
dec208a3-cba9-4239-8808-920aa54ea587
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,148
supabase-export-v2
6d38134f94d0947f
Calling functions on elements ----------------------------- The :mod:`operator` module contains a set of functions corresponding to Python's operators. Some examples are :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrget...
trusted_official_docs
CPython Docs
Calling functions on elements ----------------------------- The :mod:`operator` module contains a set of functions corresponding to Python's operators. Some examples are :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrget...
Calling functions on elements ----------------------------- The :mod:`operator` module contains a set of functions corresponding to Python's operators. Some examples are :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrget...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e02a99ec-277a-44d5-8cc6-9102c04d4a16
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,166
supabase-export-v2
900baa0ebb9afec3
The :func:`itertools.combinations(iterable, r) <itertools.combinations>` returns an iterator giving all possible *r*-tuple combinations of the elements contained in *iterable*. :: itertools.combinations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
trusted_official_docs
CPython Docs
The :func:`itertools.combinations(iterable, r) <itertools.combinations>` returns an iterator giving all possible *r*-tuple combinations of the elements contained in *iterable*. :: itertools.combinations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
The :func:`itertools.combinations(iterable, r) <itertools.combinations>` returns an iterator giving all possible *r*-tuple combinations of the elements contained in *iterable*. :: itertools.combinations([1, 2, 3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
python, official-docs, cpython, P0
Local_Trusted_Corpus
e0cbc971-9cd1-43bf-89d2-939e25d690bf
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,089
supabase-export-v2
472d95cf842f3cc4
This method resumes the generator's code and the ``yield`` expression returns the specified value. If the regular :meth:`~generator.__next__` method is called, the ``yield`` returns ``None``. Here's a simple counter that increments by 1 and allows changing the value of the internal counter.
trusted_official_docs
CPython Docs
This method resumes the generator's code and the ``yield`` expression returns the specified value. If the regular :meth:`~generator.__next__` method is called, the ``yield`` returns ``None``. Here's a simple counter that increments by 1 and allows changing the value of the internal counter.
This method resumes the generator's code and the ``yield`` expression returns the specified value. If the regular :meth:`~generator.__next__` method is called, the ``yield`` returns ``None``. Here's a simple counter that increments by 1 and allows changing the value of the internal counter.
python, official-docs, cpython, P0
Local_Trusted_Corpus
e26a3c00-fb0f-464a-b67e-aca075c26ba5
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,207
supabase-export-v2
b7251d634c7b69fc
Some of the functions in this module are: * Math operations: ``add()``, ``sub()``, ``mul()``, ``floordiv()``, ``abs()``, ... * Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object i...
trusted_official_docs
CPython Docs
Some of the functions in this module are: * Math operations: ``add()``, ``sub()``, ``mul()``, ``floordiv()``, ``abs()``, ... * Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object i...
Some of the functions in this module are: * Math operations: ``add()``, ``sub()``, ``mul()``, ``floordiv()``, ``abs()``, ... * Logical operations: ``not_()``, ``truth()``. * Bitwise operations: ``and_()``, ``or_()``, ``invert()``. * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``. * Object i...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e397037b-8da0-4f86-9315-20d771587356
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,176
supabase-export-v2
392b17f6d60530c3
single tuple. Conceptually an element is selected for the first position of each tuple and then is replaced before the second element is selected. :: itertools.combinations_with_replacement([1, 2, 3, 4, 5], 2) => (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5), (4, 4),...
trusted_official_docs
CPython Docs
single tuple. Conceptually an element is selected for the first position of each tuple and then is replaced before the second element is selected. :: itertools.combinations_with_replacement([1, 2, 3, 4, 5], 2) => (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5), (4, 4),...
single tuple. Conceptually an element is selected for the first position of each tuple and then is replaced before the second element is selected. :: itertools.combinations_with_replacement([1, 2, 3, 4, 5], 2) => (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5), (4, 4),...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ea433ee5-7be3-47be-b6aa-dd7802bcd798
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
56,989
supabase-export-v2
d7fc1d4c55d94e64
programs are lists of instructions that tell the computer what to do with the program's input. C, Pascal, and even Unix shells are procedural languages. * In **declarative** languages, you write a specification that describes the problem to be solved, and the language implementation figures out how to perform the com...
trusted_official_docs
CPython Docs
programs are lists of instructions that tell the computer what to do with the program's input. C, Pascal, and even Unix shells are procedural languages. * In **declarative** languages, you write a specification that describes the problem to be solved, and the language implementation figures out how to perform the com...
programs are lists of instructions that tell the computer what to do with the program's input. C, Pascal, and even Unix shells are procedural languages. * In **declarative** languages, you write a specification that describes the problem to be solved, and the language implementation figures out how to perform the com...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ea90ee0e-ff61-48c0-8ab9-19c8141017e4
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,201
supabase-export-v2
572f0cc95d13cf3b
# You can write: product = 1 for i in [1, 2, 3]: product *= i A related function is :func:`itertools.accumulate(iterable, func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each ...
trusted_official_docs
CPython Docs
# You can write: product = 1 for i in [1, 2, 3]: product *= i A related function is :func:`itertools.accumulate(iterable, func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each ...
# You can write: product = 1 for i in [1, 2, 3]: product *= i A related function is :func:`itertools.accumulate(iterable, func=operator.add) <itertools.accumulate>`. It performs the same calculation, but instead of returning only the final result, :func:`~itertools.accumulate` returns an iterator that also yields each ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ec3eebaf-a4a4-44ee-896d-9ed9b45a9f2e
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,184
supabase-export-v2
211ab4e791d0f9e7
itertools.groupby(city_list, get_state) => ('AL', iterator-1), ('AK', iterator-2), ('AZ', iterator-3), ... where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
trusted_official_docs
CPython Docs
itertools.groupby(city_list, get_state) => ('AL', iterator-1), ('AK', iterator-2), ('AZ', iterator-3), ... where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
itertools.groupby(city_list, get_state) => ('AL', iterator-1), ('AK', iterator-2), ('AZ', iterator-3), ... where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
python, official-docs, cpython, P0
Local_Trusted_Corpus
f00c2c3a-0e19-49e1-baf2-401cb9ced25a
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,173
supabase-export-v2
1896429a533bef92
Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique:: itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
trusted_official_docs
CPython Docs
Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique:: itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
Note that these functions produce all of the possible combinations by position and don't require that the contents of *iterable* are unique:: itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
python, official-docs, cpython, P0
Local_Trusted_Corpus
f0b6ee2a-fcce-4715-b7c1-4116e4547793
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,033
supabase-export-v2
5cc80d710053cb07
Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys:: >>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, ... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} >>> for key in m: ... print(key, m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun...
trusted_official_docs
CPython Docs
Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys:: >>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, ... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} >>> for key in m: ... print(key, m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun...
Calling :func:`iter` on a dictionary returns an iterator that will loop over the dictionary's keys:: >>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, ... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} >>> for key in m: ... print(key, m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun...
python, official-docs, cpython, P0
Local_Trusted_Corpus
f0c71cb9-d801-47bc-af5d-600bb1dd46f2
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,205
supabase-export-v2
3ce3f1d799d8afb2
The operator module ------------------- The :mod:`operator` module was mentioned earlier. It contains a set of functions corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
trusted_official_docs
CPython Docs
The operator module ------------------- The :mod:`operator` module was mentioned earlier. It contains a set of functions corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
The operator module ------------------- The :mod:`operator` module was mentioned earlier. It contains a set of functions corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
python, official-docs, cpython, P0
Local_Trusted_Corpus
f178e74b-6cdd-4c65-9df9-70617c23e7d8
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,113
supabase-export-v2
9ffbc0db5ddd870b
>>> list(x for x in range(10) if is_even(x)) [0, 2, 4, 6, 8] :func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. ::
trusted_official_docs
CPython Docs
>>> list(x for x in range(10) if is_even(x)) [0, 2, 4, 6, 8] :func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. ::
>>> list(x for x in range(10) if is_even(x)) [0, 2, 4, 6, 8] :func:`enumerate(iter, start=0) <enumerate>` counts off the elements in the iterable returning 2-tuples containing the count (from *start*) and each element. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
f276615d-ec8c-4b66-8909-f18eef391982
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,167
supabase-export-v2
afa4391698e85c24
3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) itertools.combinations([1, 2, 3, 4, 5], 3) => (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5)
trusted_official_docs
CPython Docs
3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) itertools.combinations([1, 2, 3, 4, 5], 3) => (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5)
3, 4, 5], 2) => (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) itertools.combinations([1, 2, 3, 4, 5], 3) => (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5)
python, official-docs, cpython, P0
Local_Trusted_Corpus
f2e0b166-537c-479b-bbad-d56f4e49b072
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,144
supabase-export-v2
db04aa6949b9c3c3
iterator, so this can consume significant memory if the iterator is large and one of the new iterators is consumed more than the others. :: itertools.tee( itertools.count() ) => iterA, iterB
trusted_official_docs
CPython Docs
iterator, so this can consume significant memory if the iterator is large and one of the new iterators is consumed more than the others. :: itertools.tee( itertools.count() ) => iterA, iterB
iterator, so this can consume significant memory if the iterator is large and one of the new iterators is consumed more than the others. :: itertools.tee( itertools.count() ) => iterA, iterB
python, official-docs, cpython, P0
Local_Trusted_Corpus
f4a0f236-e89e-497c-98d3-1b2b4996adbf
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
56,992
supabase-export-v2
059d1b48f396a9cc
state that affects the output produced for a given input. Well-known functional languages include the ML family (Standard ML, OCaml, and other variants) and Haskell. The designers of some computer languages choose to emphasize one particular approach to programming. This often makes it difficult to write programs that ...
trusted_official_docs
CPython Docs
state that affects the output produced for a given input. Well-known functional languages include the ML family (Standard ML, OCaml, and other variants) and Haskell. The designers of some computer languages choose to emphasize one particular approach to programming. This often makes it difficult to write programs that ...
state that affects the output produced for a given input. Well-known functional languages include the ML family (Standard ML, OCaml, and other variants) and Haskell. The designers of some computer languages choose to emphasize one particular approach to programming. This often makes it difficult to write programs that ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
f66bd864-a88e-456c-91d6-80fb9e3662b9
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,156
supabase-export-v2
5f059f25125604b9
returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. :: def less_than_10(x): return x < 10
trusted_official_docs
CPython Docs
returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. :: def less_than_10(x): return x < 10
returns elements for as long as the predicate returns true. Once the predicate returns false, the iterator will signal the end of its results. :: def less_than_10(x): return x < 10
python, official-docs, cpython, P0
Local_Trusted_Corpus
f762e590-8236-42f4-b38d-b5966a3b68d7
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,136
supabase-export-v2
526db4a412da4b59
a provided iterable and returns a new iterator that returns its elements from first to last. The new iterator will repeat these elements infinitely. :: itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
trusted_official_docs
CPython Docs
a provided iterable and returns a new iterator that returns its elements from first to last. The new iterator will repeat these elements infinitely. :: itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
a provided iterable and returns a new iterator that returns its elements from first to last. The new iterator will repeat these elements infinitely. :: itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
f796acc0-5bf1-4772-803a-623adb1f6ce3
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,170
supabase-export-v2
a598112b91d2a7f7
5), (3, 1), (3, 2), (3, 4), (3, 5), (4, 1), (4, 2), (4, 3), (4, 5), (5, 1), (5, 2), (5, 3), (5, 4) itertools.permutations([1, 2, 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
trusted_official_docs
CPython Docs
5), (3, 1), (3, 2), (3, 4), (3, 5), (4, 1), (4, 2), (4, 3), (4, 5), (5, 1), (5, 2), (5, 3), (5, 4) itertools.permutations([1, 2, 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
5), (3, 1), (3, 2), (3, 4), (3, 5), (4, 1), (4, 2), (4, 3), (4, 5), (5, 1), (5, 2), (5, 3), (5, 4) itertools.permutations([1, 2, 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
python, official-docs, cpython, P0
Local_Trusted_Corpus
fae14309-62e4-4d54-931c-f50589e8a42e
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
56,984
supabase-export-v2
5ca9bac2e2c3f50f
:Author: \A. M. Kuchling :Release: 0.32 In this document, we'll take a tour of Python's features suitable for implementing programs in a functional style. After an introduction to the concepts of functional programming, we'll look at language features such as :term:`iterator`\s and :term:`generator`\s and relevant libr...
trusted_official_docs
CPython Docs
:Author: \A. M. Kuchling :Release: 0.32 In this document, we'll take a tour of Python's features suitable for implementing programs in a functional style. After an introduction to the concepts of functional programming, we'll look at language features such as :term:`iterator`\s and :term:`generator`\s and relevant libr...
:Author: \A. M. Kuchling :Release: 0.32 In this document, we'll take a tour of Python's features suitable for implementing programs in a functional style. After an introduction to the concepts of functional programming, we'll look at language features such as :term:`iterator`\s and :term:`generator`\s and relevant libr...
python, official-docs, cpython, P0
Local_Trusted_Corpus
fb27e9e7-f9f2-4a88-97db-5496dcdb33bb
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,078
supabase-export-v2
50a519f163ab88c0
Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting examples. Here's one generator that implements an in-order traversal of a tree using generators recursively. :: # A recursive generator that generates Tree leaves in in-order. def inorder(t): if t: for x in inorder(t.left):...
trusted_official_docs
CPython Docs
Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting examples. Here's one generator that implements an in-order traversal of a tree using generators recursively. :: # A recursive generator that generates Tree leaves in in-order. def inorder(t): if t: for x in inorder(t.left):...
Python's library, :source:`Lib/test/test_generators.py`, contains a number of more interesting examples. Here's one generator that implements an in-order traversal of a tree using generators recursively. :: # A recursive generator that generates Tree leaves in in-order. def inorder(t): if t: for x in inorder(t.left):...
python, official-docs, cpython, P0
Local_Trusted_Corpus
fb9c47f0-5185-49aa-9acd-c6e3f5fe8d6c
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,066
supabase-export-v2
c9983abdb09f291d
Generators ========== Generators are a special class of functions that simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values.
trusted_official_docs
CPython Docs
Generators ========== Generators are a special class of functions that simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values.
Generators ========== Generators are a special class of functions that simplify the task of writing iterators. Regular functions compute a value and return it, but generators return an iterator that returns a stream of values.
python, official-docs, cpython, P0
Local_Trusted_Corpus
fc07f231-c305-4001-851c-63735e0a47b3
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,242
supabase-export-v2
aa8b53bd1004d75b
a program. The book uses Scheme for its examples, but many of the design approaches described in these chapters are applicable to functional-style Python code. https://defmacro.org/2006/06/19/fp.html: A general introduction to functional programming that uses Java examples and has a lengthy historical introduction.
trusted_official_docs
CPython Docs
a program. The book uses Scheme for its examples, but many of the design approaches described in these chapters are applicable to functional-style Python code. https://defmacro.org/2006/06/19/fp.html: A general introduction to functional programming that uses Java examples and has a lengthy historical introduction.
a program. The book uses Scheme for its examples, but many of the design approaches described in these chapters are applicable to functional-style Python code. https://defmacro.org/2006/06/19/fp.html: A general introduction to functional programming that uses Java examples and has a lengthy historical introduction.
python, official-docs, cpython, P0
Local_Trusted_Corpus
fdf0ee35-75db-484a-bf48-2de3e3090a24
CPython Docs
file://datasets/cpython/Doc/howto/functional.rst
unknown
96a5a3c7-7880-46e2-a48a-2e8064e3ea09
57,213
supabase-export-v2
e204541b2e1a5942
stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list) If the function you need doesn't exist, you need to write it. One way to write small functions is to use the :keyword:`lambda` expression. ``lambda`` takes a number of parameters and an expression combining these parame...
trusted_official_docs
CPython Docs
stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list) If the function you need doesn't exist, you need to write it. One way to write small functions is to use the :keyword:`lambda` expression. ``lambda`` takes a number of parameters and an expression combining these parame...
stripped_lines = [line.strip() for line in lines] existing_files = filter(os.path.exists, file_list) If the function you need doesn't exist, you need to write it. One way to write small functions is to use the :keyword:`lambda` expression. ``lambda`` takes a number of parameters and an expression combining these parame...
python, official-docs, cpython, P0
Local_Trusted_Corpus
134828a5-4981-4d46-b1ad-0d65b5d5c3a4
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,282
supabase-export-v2
a3b92bad7233b7c3
count = int.from_bytes(os.read(fd, 8), byteorder=sys.byteorder) print(f"Timer {fds.index(fd) + 1} expired {count} times") else: print(f"Unknown file descriptor {fd}") finally: for fd in fds: ep.unregister(fd) os.close(fd) ep.close() This example shows how :func:`~select.select` can be used with timer file descriptors t...
trusted_official_docs
CPython Docs
count = int.from_bytes(os.read(fd, 8), byteorder=sys.byteorder) print(f"Timer {fds.index(fd) + 1} expired {count} times") else: print(f"Unknown file descriptor {fd}") finally: for fd in fds: ep.unregister(fd) os.close(fd) ep.close() This example shows how :func:`~select.select` can be used with timer file descriptors t...
count = int.from_bytes(os.read(fd, 8), byteorder=sys.byteorder) print(f"Timer {fds.index(fd) + 1} expired {count} times") else: print(f"Unknown file descriptor {fd}") finally: for fd in fds: ep.unregister(fd) os.close(fd) ep.close() This example shows how :func:`~select.select` can be used with timer file descriptors t...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1b464732-2a79-43c2-931c-2c478f352d71
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,281
supabase-export-v2
08dc853cd7e2a264
print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, close connection print(f"Closing connect...
trusted_official_docs
CPython Docs
print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, close connection print(f"Closing connect...
print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, close connection print(f"Closing connect...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1db49a46-0698-4941-a85c-294b5dd20420
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,274
supabase-export-v2
7813970eb695e7f3
# Create an epoll object ep = select.epoll() # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket...
trusted_official_docs
CPython Docs
# Create an epoll object ep = select.epoll() # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket...
# Create an epoll object ep = select.epoll() # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket...
python, official-docs, cpython, P0
Local_Trusted_Corpus
28643ee7-6d3b-4c3f-8ba8-ffcb08647be2
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,275
supabase-export-v2
7705ffad425c600a
127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) ep.register(sock, select.EPOLLIN) # Create timer file descriptors in non-blocking mode. num = 3 fds = [] f...
trusted_official_docs
CPython Docs
127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) ep.register(sock, select.EPOLLIN) # Create timer file descriptors in non-blocking mode. num = 3 fds = [] f...
127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) ep.register(sock, select.EPOLLIN) # Create timer file descriptors in non-blocking mode. num = 3 fds = [] f...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2d89a10e-ce09-4042-ad70-402c1495db75
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,278
supabase-export-v2
4c4ce430ed24e033
and conn[=returned value of socket.accept()] are socket objects, not file descriptors. # So use sock.fileno() and conn.fileno() to get the file descriptors. events = ep.poll(timeout) # If more than one timer file descriptors are ready for reading at once, # epoll.poll() returns a list of (fd, event) pairs. # # In thi...
trusted_official_docs
CPython Docs
and conn[=returned value of socket.accept()] are socket objects, not file descriptors. # So use sock.fileno() and conn.fileno() to get the file descriptors. events = ep.poll(timeout) # If more than one timer file descriptors are ready for reading at once, # epoll.poll() returns a list of (fd, event) pairs. # # In thi...
and conn[=returned value of socket.accept()] are socket objects, not file descriptors. # So use sock.fileno() and conn.fileno() to get the file descriptors. events = ep.poll(timeout) # If more than one timer file descriptors are ready for reading at once, # epoll.poll() returns a list of (fd, event) pairs. # # In thi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
49aa5986-c288-4209-848a-0b91e5c23147
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,270
supabase-export-v2
5fe16ae63014e6f2
precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanoseconds with ``_ns`` variants of the functions. This example shows how :func:`~select.epoll` can be used with timer file descriptors to wait until the file descriptor is ready for rea...
trusted_official_docs
CPython Docs
precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanoseconds with ``_ns`` variants of the functions. This example shows how :func:`~select.epoll` can be used with timer file descriptors to wait until the file descriptor is ready for rea...
precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanoseconds with ``_ns`` variants of the functions. This example shows how :func:`~select.epoll` can be used with timer file descriptors to wait until the file descriptor is ready for rea...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6e48bc55-50a5-4f3e-97da-a9a2848578d0
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,279
supabase-export-v2
6c4788bcfad96975
In 0.75 seconds, 1st timer and 3rd timer fires at once. # In 1.5 seconds, 1st timer, 2nd timer and 3rd timer fires at once. # # If a timer file descriptor is signaled more than once since # the last os.read() call, os.read() returns the number of signaled # as host order of class bytes. print(f"Signaled events={even...
trusted_official_docs
CPython Docs
In 0.75 seconds, 1st timer and 3rd timer fires at once. # In 1.5 seconds, 1st timer, 2nd timer and 3rd timer fires at once. # # If a timer file descriptor is signaled more than once since # the last os.read() call, os.read() returns the number of signaled # as host order of class bytes. print(f"Signaled events={even...
In 0.75 seconds, 1st timer and 3rd timer fires at once. # In 1.5 seconds, 1st timer, 2nd timer and 3rd timer fires at once. # # If a timer file descriptor is signaled more than once since # the last os.read() call, os.read() returns the number of signaled # as host order of class bytes. print(f"Signaled events={even...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8c4f4d99-b9b4-478d-9e98-3c7f9f15cfa5
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,288
supabase-export-v2
b47c3a64bbceaa7a
os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): os.timerfd_settime(fd, initial=i/4, interval=i/4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # select.select() ...
trusted_official_docs
CPython Docs
os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): os.timerfd_settime(fd, initial=i/4, interval=i/4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # select.select() ...
os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): os.timerfd_settime(fd, initial=i/4, interval=i/4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # select.select() ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
90dc3af9-15d1-476b-a0df-220ecd663ebf
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,266
supabase-export-v2
1c745d5fef6f89ab
# Practical scripts should use really use a non-blocking timer, # we use a blocking timer here for simplicity. import os, time # Create the timer file descriptor fd = os.timerfd_create(time.CLOCK_REALTIME)
trusted_official_docs
CPython Docs
# Practical scripts should use really use a non-blocking timer, # we use a blocking timer here for simplicity. import os, time # Create the timer file descriptor fd = os.timerfd_create(time.CLOCK_REALTIME)
# Practical scripts should use really use a non-blocking timer, # we use a blocking timer here for simplicity. import os, time # Create the timer file descriptor fd = os.timerfd_create(time.CLOCK_REALTIME)
python, official-docs, cpython, P0
Local_Trusted_Corpus
9dc7429b-aff9-4966-9cfa-88213a14ea60
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,276
supabase-export-v2
38a77849f7c3eb42
= 3 fds = [] for _ in range(num): fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) fds.append(fd) # Register the timer file descriptor for read events ep.register(fd, select.EPOLLIN) # Start the timer with os.timerfd_settime_ns() in nanoseconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 se...
trusted_official_docs
CPython Docs
= 3 fds = [] for _ in range(num): fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) fds.append(fd) # Register the timer file descriptor for read events ep.register(fd, select.EPOLLIN) # Start the timer with os.timerfd_settime_ns() in nanoseconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 se...
= 3 fds = [] for _ in range(num): fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) fds.append(fd) # Register the timer file descriptor for read events ep.register(fd, select.EPOLLIN) # Start the timer with os.timerfd_settime_ns() in nanoseconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 se...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b704038c-2cb2-499c-b08a-06057b161434
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,280
supabase-export-v2
546670144daf2fe7
addr = sock.accept() conn.setblocking(False) print(f"Accepted connection {conn} from {addr}") ep.register(conn, select.EPOLLIN) elif conn and fd == conn.fileno(): # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety.
trusted_official_docs
CPython Docs
addr = sock.accept() conn.setblocking(False) print(f"Accepted connection {conn} from {addr}") ep.register(conn, select.EPOLLIN) elif conn and fd == conn.fileno(): # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety.
addr = sock.accept() conn.setblocking(False) print(f"Accepted connection {conn} from {addr}") ep.register(conn, select.EPOLLIN) elif conn and fd == conn.fileno(): # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety.
python, official-docs, cpython, P0
Local_Trusted_Corpus
bddc4a12-fee3-4629-ab6d-a483868a5613
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,289
supabase-export-v2
4b0aad4f8fd0a7be
conn: # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, c...
trusted_official_docs
CPython Docs
conn: # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, c...
conn: # Check if there is data to read. print(f"Reading data {fd}") data = conn.recv(1024) if data: # You should catch UnicodeDecodeError exception for safety. cmd = data.decode() if cmd.startswith("stop"): print(f"Stopping server") is_active = False else: print(f"Unknown command: {cmd}") else: # No more data, c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c467a058-629f-45a1-9dfb-505147e6cd0e
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,286
supabase-export-v2
05931d3dacd8cb71
Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) # Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CL...
trusted_official_docs
CPython Docs
Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) # Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CL...
Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) sock.setblocking(False) sock.listen(1) # Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CL...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d7024602-7c90-45e0-b027-a7a8c62a1c16
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,277
supabase-export-v2
e0c2713da5d2dbd8
0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): one_sec_in_nsec = 10**9 i = i * one_sec_in_nsec os.timerfd_settime_ns(fd, initial=i//4, interval=i//4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # epoll.poll() retur...
trusted_official_docs
CPython Docs
0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): one_sec_in_nsec = 10**9 i = i * one_sec_in_nsec os.timerfd_settime_ns(fd, initial=i//4, interval=i//4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # epoll.poll() retur...
0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enumerate(fds, start=1): one_sec_in_nsec = 10**9 i = i * one_sec_in_nsec os.timerfd_settime_ns(fd, initial=i//4, interval=i//4) timeout = 3 try: conn = None is_active = True while is_active: # Wait for the timer to expire for 3 seconds. # epoll.poll() retur...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d806a280-e2a8-42b5-af98-c4aae0b4207b
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,287
supabase-export-v2
50fa395eea9c3c2c
# Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) for _ in range(num)] select_fds = fds + [sock] # Start the timers with os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enum...
trusted_official_docs
CPython Docs
# Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) for _ in range(num)] select_fds = fds + [sock] # Start the timers with os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enum...
# Create timer file descriptors in non-blocking mode. num = 3 fds = [os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) for _ in range(num)] select_fds = fds + [sock] # Start the timers with os.timerfd_settime() in seconds. # Timer 1 fires every 0.25 seconds; timer 2 every 0.5 seconds; etc for i, fd in enum...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d9973a7e-d6ae-4498-aef9-f6dac4de20dc
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,269
supabase-export-v2
d84c711bfa4db2a9
range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! os.close(fd) To avoid the precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanosecon...
trusted_official_docs
CPython Docs
range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! os.close(fd) To avoid the precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanosecon...
range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! os.close(fd) To avoid the precision loss caused by the :class:`float` type, timer file descriptors allow specifying initial expiration and interval in integer nanosecon...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ec5240e1-2675-4089-9af7-076083a8b250
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,268
supabase-export-v2
3636c6b08e5e46df
# Start the timer in 1 second, with an interval of half a second os.timerfd_settime(fd, initial=1, interval=0.5) try: # Process timer events four times. for _ in range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! ...
trusted_official_docs
CPython Docs
# Start the timer in 1 second, with an interval of half a second os.timerfd_settime(fd, initial=1, interval=0.5) try: # Process timer events four times. for _ in range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! ...
# Start the timer in 1 second, with an interval of half a second os.timerfd_settime(fd, initial=1, interval=0.5) try: # Process timer events four times. for _ in range(4): # read() will block until the timer expires _ = os.read(fd, 8) print("Timer expired") finally: # Remember to close the timer file descriptor! ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
fea95a94-cce7-493e-b5c5-bca2d5b04fbd
CPython Docs
file://datasets/cpython/Doc/howto/timerfd.rst
unknown
a0f480cc-ca69-43bf-8994-769744fb75d9
57,285
supabase-export-v2
ecb77281e6eb2408
import os, time, select, socket, sys # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_ST...
trusted_official_docs
CPython Docs
import os, time, select, socket, sys # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_ST...
import os, time, select, socket, sys # In this example, use loopback address to send "stop" command to the server. # # $ telnet 127.0.0.1 1234 # Trying 127.0.0.1... # Connected to 127.0.0.1. # Escape character is '^]'. # stop # Connection closed by foreign host. # sock = socket.socket(socket.AF_INET, socket.SOCK_ST...
python, official-docs, cpython, P0
Local_Trusted_Corpus
0175d88c-1091-4977-9d31-affa591aae58
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,303
supabase-export-v2
6bd2280de09420ce
you build CPython from source, debugging information should be available, and the build should add a ``python-gdb.py`` file to the root directory of your repository. To activate support, you must add the directory containing ``python-gdb.py`` to GDB's "auto-load-safe-path". If you haven't done this, recent versions of ...
trusted_official_docs
CPython Docs
you build CPython from source, debugging information should be available, and the build should add a ``python-gdb.py`` file to the root directory of your repository. To activate support, you must add the directory containing ``python-gdb.py`` to GDB's "auto-load-safe-path". If you haven't done this, recent versions of ...
you build CPython from source, debugging information should be available, and the build should add a ``python-gdb.py`` file to the root directory of your repository. To activate support, you must add the directory containing ``python-gdb.py`` to GDB's "auto-load-safe-path". If you haven't done this, recent versions of ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
02bcb96d-6251-462a-86a9-ce4dad98a71e
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,329
supabase-export-v2
1673f612bf3636a7
Note that the pretty-printers do not actually call ``repr()``. For basic types, they try to match its result closely. An area that can be confusing is that the custom printer for some types look a lot like GDB's built-in printer for standard types. For example, the pretty-printer for a Python ``int`` (:c:expr:`PyLongOb...
trusted_official_docs
CPython Docs
Note that the pretty-printers do not actually call ``repr()``. For basic types, they try to match its result closely. An area that can be confusing is that the custom printer for some types look a lot like GDB's built-in printer for standard types. For example, the pretty-printer for a Python ``int`` (:c:expr:`PyLongOb...
Note that the pretty-printers do not actually call ``repr()``. For basic types, they try to match its result closely. An area that can be confusing is that the custom printer for some types look a lot like GDB's built-in printer for standard types. For example, the pretty-printer for a Python ``int`` (:c:expr:`PyLongOb...
python, official-docs, cpython, P0
Local_Trusted_Corpus
03498124-ab91-46b3-bae4-a9c7e7d87c57
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,378
supabase-export-v2
ac4786ea12e55a47
(gdb) t a a py-bt Thread 105 (Thread 0x7fffefa18710 (LWP 10260)): #5 Frame 0x7fffd00019d0, for file /home/david/coding/python-svn/Lib/threading.py, line 155, in _acquire_restore (self=<_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=<thread.lock at remote 0x858770>, _RLock__count=1) at rem...
trusted_official_docs
CPython Docs
(gdb) t a a py-bt Thread 105 (Thread 0x7fffefa18710 (LWP 10260)): #5 Frame 0x7fffd00019d0, for file /home/david/coding/python-svn/Lib/threading.py, line 155, in _acquire_restore (self=<_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=<thread.lock at remote 0x858770>, _RLock__count=1) at rem...
(gdb) t a a py-bt Thread 105 (Thread 0x7fffefa18710 (LWP 10260)): #5 Frame 0x7fffd00019d0, for file /home/david/coding/python-svn/Lib/threading.py, line 155, in _acquire_restore (self=<_RLock(_Verbose__verbose=False, _RLock__owner=140737354016512, _RLock__block=<thread.lock at remote 0x858770>, _RLock__count=1) at rem...
python, official-docs, cpython, P0
Local_Trusted_Corpus
0648c5b7-19d1-4a84-ad64-ae9ae90eafe9
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,324
supabase-export-v2
d44ad91b0f4363a0
remote 0xaacd80>, 'dict': {0: 0, 1: 1, 2: 2, 3: 3}, '__name__': '__main__', 'z': <Yuck(i=0) at remote 0xaace60>, '__doc__': None}, key= 0x5c2b8d "__lltrace__") at Objects/dictobject.c:2171 Notice how the dictionary argument to ``PyDict_GetItemString`` is displayed as its ``repr()``, rather than an opaque ``PyObject *``...
trusted_official_docs
CPython Docs
remote 0xaacd80>, 'dict': {0: 0, 1: 1, 2: 2, 3: 3}, '__name__': '__main__', 'z': <Yuck(i=0) at remote 0xaace60>, '__doc__': None}, key= 0x5c2b8d "__lltrace__") at Objects/dictobject.c:2171 Notice how the dictionary argument to ``PyDict_GetItemString`` is displayed as its ``repr()``, rather than an opaque ``PyObject *``...
remote 0xaacd80>, 'dict': {0: 0, 1: 1, 2: 2, 3: 3}, '__name__': '__main__', 'z': <Yuck(i=0) at remote 0xaace60>, '__doc__': None}, key= 0x5c2b8d "__lltrace__") at Objects/dictobject.c:2171 Notice how the dictionary argument to ``PyDict_GetItemString`` is displayed as its ``repr()``, rather than an opaque ``PyObject *``...
python, official-docs, cpython, P0
Local_Trusted_Corpus
08576a4f-03d5-4cbc-bbe3-c9dcf917ae72
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,323
supabase-export-v2
3ea9a947d06acf5d
This is what a GDB backtrace looks like (truncated) when this extension is enabled:: #0 0x000000000041a6b1 in PyObject_Malloc (nbytes=Cannot access memory at address 0x7fffff7fefe8 ) at Objects/obmalloc.c:748 #1 0x000000000041b7c0 in _PyObject_DebugMallocApi (id=111 'o', nbytes=24) at Objects/obmalloc.c:1445 #2 0x00...
trusted_official_docs
CPython Docs
This is what a GDB backtrace looks like (truncated) when this extension is enabled:: #0 0x000000000041a6b1 in PyObject_Malloc (nbytes=Cannot access memory at address 0x7fffff7fefe8 ) at Objects/obmalloc.c:748 #1 0x000000000041b7c0 in _PyObject_DebugMallocApi (id=111 'o', nbytes=24) at Objects/obmalloc.c:1445 #2 0x00...
This is what a GDB backtrace looks like (truncated) when this extension is enabled:: #0 0x000000000041a6b1 in PyObject_Malloc (nbytes=Cannot access memory at address 0x7fffff7fefe8 ) at Objects/obmalloc.c:748 #1 0x000000000041b7c0 in _PyObject_DebugMallocApi (id=111 'o', nbytes=24) at Objects/obmalloc.c:1445 #2 0x00...
python, official-docs, cpython, P0
Local_Trusted_Corpus
18efe2fd-eaee-46de-9c9a-c2ee92541a5d
CPython Docs
file://datasets/cpython/Doc/howto/gdb_helpers.rst
unknown
4697ae04-90df-4433-841a-1333ce583038
57,295
supabase-export-v2
b2cd0ee07e463742
of currently executing Python functions. Given a Python object represented by a :c:expr:`PyObject *` pointer, the extension surfaces the type and value of the object. Developers who are working on CPython extensions or tinkering with parts of CPython that are written in C can use this document to learn how to use the `...
trusted_official_docs
CPython Docs
of currently executing Python functions. Given a Python object represented by a :c:expr:`PyObject *` pointer, the extension surfaces the type and value of the object. Developers who are working on CPython extensions or tinkering with parts of CPython that are written in C can use this document to learn how to use the `...
of currently executing Python functions. Given a Python object represented by a :c:expr:`PyObject *` pointer, the extension surfaces the type and value of the object. Developers who are working on CPython extensions or tinkering with parts of CPython that are written in C can use this document to learn how to use the `...
python, official-docs, cpython, P0
Local_Trusted_Corpus