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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
e5257189-e37e-406b-8474-4b2a860ce8f3 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,848 | supabase-export-v2 | 8aceae9c3b6005eb | is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode such floats.
If *sort_keys* is true (default: ``False``), then the output of dictionaries
will be sorted by key; this is useful for regression tests to ensure tha... | trusted_official_docs | CPython Docs | is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode such floats.
If *sort_keys* is true (default: ``False``), then the output of dictionaries
will be sorted by key; this is useful for regression tests to ensure tha... | is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode such floats.
If *sort_keys* is true (default: ``False``), then the output of dictionaries
will be sorted by key; this is useful for regression tests to ensure tha... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e881560f-0932-4a2d-a62b-361e47c33746 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,797 | supabase-export-v2 | c3495bac91e56301 | :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also set, *object_pairs_hook* takes priority. Default ``None``. :type object_pairs_hook: :term:`callable` | None
:param array_hook:
If set, a function that is called with the result of
any JSON array literal decoded with as a Py... | trusted_official_docs | CPython Docs | :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also set, *object_pairs_hook* takes priority. Default ``None``. :type object_pairs_hook: :term:`callable` | None
:param array_hook:
If set, a function that is called with the result of
any JSON array literal decoded with as a Py... | :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also set, *object_pairs_hook* takes priority. Default ``None``. :type object_pairs_hook: :term:`callable` | None
:param array_hook:
If set, a function that is called with the result of
any JSON array literal decoded with as a Py... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ea11a863-1290-4f3a-b8c4-8e582b5c3b03 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,897 | supabase-export-v2 | c7fbc915344c82b5 | Top-level Non-Object, Non-Array Values ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The old version of JSON specified by the obsolete :rfc:`4627` required that
the top-level value of a JSON text must be either a JSON object or array
(Python :class:`dict` or :class:`list`), and could not be a JSON null,
boolean, number, or st... | trusted_official_docs | CPython Docs | Top-level Non-Object, Non-Array Values ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The old version of JSON specified by the obsolete :rfc:`4627` required that
the top-level value of a JSON text must be either a JSON object or array
(Python :class:`dict` or :class:`list`), and could not be a JSON null,
boolean, number, or st... | Top-level Non-Object, Non-Array Values ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The old version of JSON specified by the obsolete :rfc:`4627` required that
the top-level value of a JSON text must be either a JSON object or array
(Python :class:`dict` or :class:`list`), and could not be a JSON null,
boolean, number, or st... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ec49afa1-cdf4-4494-a823-0670f11b0775 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,795 | supabase-export-v2 | adfb414d4df6f22b | Additional keyword arguments to :func:`!load` will be passed to the constructor of *cls*. If ``None`` (the default), :class:`!JSONDecoder` is used. :type cls: a :class:`JSONDecoder` subclass
:param object_hook:
If set, a function that is called with the result of
any JSON object literal decoded (a :class:`dict`). The... | trusted_official_docs | CPython Docs | Additional keyword arguments to :func:`!load` will be passed to the constructor of *cls*. If ``None`` (the default), :class:`!JSONDecoder` is used. :type cls: a :class:`JSONDecoder` subclass
:param object_hook:
If set, a function that is called with the result of
any JSON object literal decoded (a :class:`dict`). The... | Additional keyword arguments to :func:`!load` will be passed to the constructor of *cls*. If ``None`` (the default), :class:`!JSONDecoder` is used. :type cls: a :class:`JSONDecoder` subclass
:param object_hook:
If set, a function that is called with the result of
any JSON object literal decoded (a :class:`dict`). The... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f1afea6d-90c9-46bc-9149-4b059e2ca7a3 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,836 | supabase-export-v2 | e540cb9c7c087abe | *s* (a :class:`str` beginning with a JSON document) and return a 2-tuple of the Python representation and the index in *s* where the document ended.
This can be used to decode a JSON document from a string that may have
extraneous data at the end. | trusted_official_docs | CPython Docs | *s* (a :class:`str` beginning with a JSON document) and return a 2-tuple of the Python representation and the index in *s* where the document ended.
This can be used to decode a JSON document from a string that may have
extraneous data at the end. | *s* (a :class:`str` beginning with a JSON document) and return a 2-tuple of the Python representation and the index in *s* where the document ended.
This can be used to decode a JSON document from a string that may have
extraneous data at the end. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f2db8155-1077-48be-b31c-a4dcd4e4ebdc | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,843 | supabase-export-v2 | e8f2211b46e5400a | .. versionchanged:: 3.4 Added support for int- and float-derived Enum classes.
To extend this to recognize other objects, subclass and implement a
:meth:`~JSONEncoder.default` method with another method that returns a serializable object
for ``o`` if possible, otherwise it should call the superclass implementation
(... | trusted_official_docs | CPython Docs | .. versionchanged:: 3.4 Added support for int- and float-derived Enum classes.
To extend this to recognize other objects, subclass and implement a
:meth:`~JSONEncoder.default` method with another method that returns a serializable object
for ``o`` if possible, otherwise it should call the superclass implementation
(... | .. versionchanged:: 3.4 Added support for int- and float-derived Enum classes.
To extend this to recognize other objects, subclass and implement a
:meth:`~JSONEncoder.default` method with another method that returns a serializable object
for ``o`` if possible, otherwise it should call the superclass implementation
(... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f4d89d62-b74a-4da3-a023-5ea01c1541c4 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,910 | supabase-export-v2 | d7dd88c9240f6c65 | The :mod:`!json` module can be invoked as a script via ``python -m json`` to validate and pretty-print JSON objects. The :mod:`!json.tool` submodule implements this interface.
If the optional ``infile`` and ``outfile`` arguments are not
specified, :data:`sys.stdin` and :data:`sys.stdout` will be used respectively: | trusted_official_docs | CPython Docs | The :mod:`!json` module can be invoked as a script via ``python -m json`` to validate and pretty-print JSON objects. The :mod:`!json.tool` submodule implements this interface.
If the optional ``infile`` and ``outfile`` arguments are not
specified, :data:`sys.stdin` and :data:`sys.stdout` will be used respectively: | The :mod:`!json` module can be invoked as a script via ``python -m json`` to validate and pretty-print JSON objects. The :mod:`!json.tool` submodule implements this interface.
If the optional ``infile`` and ``outfile`` arguments are not
specified, :data:`sys.stdin` and :data:`sys.stdout` will be used respectively: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f6b5b194-26ed-403d-87f4-b879e1141881 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,812 | supabase-export-v2 | e7650349bb76d58e | .. versionchanged:: 3.6 *s* can now be of type :class:`bytes` or :class:`bytearray`. The input encoding should be UTF-8, UTF-16 or UTF-32.
.. versionchanged:: 3.9
The keyword argument *encoding* has been removed. | trusted_official_docs | CPython Docs | .. versionchanged:: 3.6 *s* can now be of type :class:`bytes` or :class:`bytearray`. The input encoding should be UTF-8, UTF-16 or UTF-32.
.. versionchanged:: 3.9
The keyword argument *encoding* has been removed. | .. versionchanged:: 3.6 *s* can now be of type :class:`bytes` or :class:`bytearray`. The input encoding should be UTF-8, UTF-16 or UTF-32.
.. versionchanged:: 3.9
The keyword argument *encoding* has been removed. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f7d2cf33-6b01-480e-8569-19b4271375b1 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,778 | supabase-export-v2 | 13db5d188709902b | check_circular: If ``False``, the circular reference check for container types is skipped and a circular reference will result in a :exc:`RecursionError` (or worse). Default ``True``.
:param bool allow_nan:
If ``False``, serialization of out-of-range :class:`float` values
(``nan``, ``inf``, ``-inf``) will result in a... | trusted_official_docs | CPython Docs | check_circular: If ``False``, the circular reference check for container types is skipped and a circular reference will result in a :exc:`RecursionError` (or worse). Default ``True``.
:param bool allow_nan:
If ``False``, serialization of out-of-range :class:`float` values
(``nan``, ``inf``, ``-inf``) will result in a... | check_circular: If ``False``, the circular reference check for container types is skipped and a circular reference will result in a :exc:`RecursionError` (or worse). Default ``True``.
:param bool allow_nan:
If ``False``, serialization of out-of-range :class:`float` values
(``nan``, ``inf``, ``-inf``) will result in a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f88e9344-29da-43ae-892d-aabb1da4d94a | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,782 | supabase-export-v2 | a173f398ca57f7ca | if *indent* is ``None``, and ``(',', ': ')`` otherwise. For the most compact JSON, specify ``(',', ':')`` to eliminate whitespace. :type separators: tuple | None
:param default:
A function that is called for objects that can't otherwise be serialized. It should return a JSON encodable version of the object
or raise a... | trusted_official_docs | CPython Docs | if *indent* is ``None``, and ``(',', ': ')`` otherwise. For the most compact JSON, specify ``(',', ':')`` to eliminate whitespace. :type separators: tuple | None
:param default:
A function that is called for objects that can't otherwise be serialized. It should return a JSON encodable version of the object
or raise a... | if *indent* is ``None``, and ``(',', ': ')`` otherwise. For the most compact JSON, specify ``(',', ':')`` to eliminate whitespace. :type separators: tuple | None
:param default:
A function that is called for objects that can't otherwise be serialized. It should return a JSON encodable version of the object
or raise a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f99aacb4-34bc-45f5-8479-d2b854384c3a | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,822 | supabase-export-v2 | 538ffa8b1e50d9ab | will be used instead of the :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also defined, the *object_pairs_hook* takes priority.
.. versionchanged:: 3.1
Added support for *object_pairs_hook*. | trusted_official_docs | CPython Docs | will be used instead of the :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also defined, the *object_pairs_hook* takes priority.
.. versionchanged:: 3.1
Added support for *object_pairs_hook*. | will be used instead of the :class:`dict`. This feature can be used to implement custom decoders. If *object_hook* is also defined, the *object_pairs_hook* takes priority.
.. versionchanged:: 3.1
Added support for *object_pairs_hook*. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fa21fc66-4ffb-4bb1-a716-ea08eacfe02d | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,759 | supabase-export-v2 | b04febf16a47f922 | Extending :class:`JSONEncoder`::
>>> import json
>>> class ComplexEncoder(json.JSONEncoder):
... def default(self, obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... # Let the base class default method raise the TypeError
... return super().default(obj)
... >>> json.dumps(2 + 1j, cls=Comp... | trusted_official_docs | CPython Docs | Extending :class:`JSONEncoder`::
>>> import json
>>> class ComplexEncoder(json.JSONEncoder):
... def default(self, obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... # Let the base class default method raise the TypeError
... return super().default(obj)
... >>> json.dumps(2 + 1j, cls=Comp... | Extending :class:`JSONEncoder`::
>>> import json
>>> class ComplexEncoder(json.JSONEncoder):
... def default(self, obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... # Let the base class default method raise the TypeError
... return super().default(obj)
... >>> json.dumps(2 + 1j, cls=Comp... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fa24dbec-643c-4a0a-84f3-409db80a81e0 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,884 | supabase-export-v2 | f5b04950b17b5fe2 | The RFC requires that JSON be represented using either UTF-8, UTF-16, or UTF-32, with UTF-8 being the recommended default for maximum interoperability.
As permitted, though not required, by the RFC, this module's serializer sets
*ensure_ascii=True* by default, thus escaping the output so that the resulting
strings only... | trusted_official_docs | CPython Docs | The RFC requires that JSON be represented using either UTF-8, UTF-16, or UTF-32, with UTF-8 being the recommended default for maximum interoperability.
As permitted, though not required, by the RFC, this module's serializer sets
*ensure_ascii=True* by default, thus escaping the output so that the resulting
strings only... | The RFC requires that JSON be represented using either UTF-8, UTF-16, or UTF-32, with UTF-8 being the recommended default for maximum interoperability.
As permitted, though not required, by the RFC, this module's serializer sets
*ensure_ascii=True* by default, thus escaping the output so that the resulting
strings only... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fb003c14-7f8f-414b-bb57-133f5555e63a | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,796 | supabase-export-v2 | cdc046126adf3555 | of the :class:`dict`. This feature can be used to implement custom decoders, for example `JSON-RPC <https://www.jsonrpc.org>`_ class hinting. Default ``None``. :type object_hook: :term:`callable` | None
:param object_pairs_hook:
If set, a function that is called with the result of
any JSON object literal decoded with... | trusted_official_docs | CPython Docs | of the :class:`dict`. This feature can be used to implement custom decoders, for example `JSON-RPC <https://www.jsonrpc.org>`_ class hinting. Default ``None``. :type object_hook: :term:`callable` | None
:param object_pairs_hook:
If set, a function that is called with the result of
any JSON object literal decoded with... | of the :class:`dict`. This feature can be used to implement custom decoders, for example `JSON-RPC <https://www.jsonrpc.org>`_ class hinting. Default ``None``. :type object_hook: :term:`callable` | None
:param object_pairs_hook:
If set, a function that is called with the result of
any JSON object literal decoded with... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fb10bcba-8516-44bc-889a-eb8f03c4ee08 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,913 | supabase-export-v2 | 2ce32aa6ba32c731 | json { "json": "obj" } $ echo '{1.2:3.4}' | python -m json Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
.. versionchanged:: 3.5
The output is now in the same order as the input. Use the
:option:`--sort-keys` option to sort the output of dictionaries
alphabetically by key. | trusted_official_docs | CPython Docs | json { "json": "obj" } $ echo '{1.2:3.4}' | python -m json Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
.. versionchanged:: 3.5
The output is now in the same order as the input. Use the
:option:`--sort-keys` option to sort the output of dictionaries
alphabetically by key. | json { "json": "obj" } $ echo '{1.2:3.4}' | python -m json Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
.. versionchanged:: 3.5
The output is now in the same order as the input. Use the
:option:`--sort-keys` option to sort the output of dictionaries
alphabetically by key. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fc590ba8-929a-415c-b046-791ddca2e7a9 | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,878 | supabase-export-v2 | 0bc86ab312fb2cbe | Standard Compliance and Interoperability ----------------------------------------
The JSON format is specified by :rfc:`7159` and by
`ECMA-404 <https://ecma-international.org/publications-and-standards/standards/ecma-404/>`_. This section details this module's level of compliance with the RFC. For simplicity, :class:`J... | trusted_official_docs | CPython Docs | Standard Compliance and Interoperability ----------------------------------------
The JSON format is specified by :rfc:`7159` and by
`ECMA-404 <https://ecma-international.org/publications-and-standards/standards/ecma-404/>`_. This section details this module's level of compliance with the RFC. For simplicity, :class:`J... | Standard Compliance and Interoperability ----------------------------------------
The JSON format is specified by :rfc:`7159` and by
`ECMA-404 <https://ecma-international.org/publications-and-standards/standards/ecma-404/>`_. This section details this module's level of compliance with the RFC. For simplicity, :class:`J... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fd842890-d6bd-4d21-bc26-90c98569056e | CPython Docs | file://datasets/cpython/Doc/library/json.rst | unknown | 7ac51696-cba9-43e9-9b4c-20273e8ce411 | 2,850 | supabase-export-v2 | 72e3106a68026900 | positive integer indent indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level.
.. versionchanged:: 3.2
Allow strings for *indent* in addition to integers. | trusted_official_docs | CPython Docs | positive integer indent indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level.
.. versionchanged:: 3.2
Allow strings for *indent* in addition to integers. | positive integer indent indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level.
.. versionchanged:: 3.2
Allow strings for *indent* in addition to integers. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0046b79e-0d7e-4b64-ba76-8d9cf2f3eda8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,265 | supabase-export-v2 | ee3cabb382ee1433 | >>> list(triplewise('ABCDEFG')) [('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E'), ('D', 'E', 'F'), ('E', 'F', 'G')]
>>> population = 'ABCDEFGH'
>>> for r in range(len(population) + 1):
... seq = list(combinations(population, r))
... for i in range(len(seq)):
... assert nth_combination(population, r, i) == seq[i]
... | trusted_official_docs | CPython Docs | >>> list(triplewise('ABCDEFG')) [('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E'), ('D', 'E', 'F'), ('E', 'F', 'G')]
>>> population = 'ABCDEFGH'
>>> for r in range(len(population) + 1):
... seq = list(combinations(population, r))
... for i in range(len(seq)):
... assert nth_combination(population, r, i) == seq[i]
... | >>> list(triplewise('ABCDEFG')) [('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E'), ('D', 'E', 'F'), ('E', 'F', 'G')]
>>> population = 'ABCDEFGH'
>>> for r in range(len(population) + 1):
... seq = list(combinations(population, r))
... for i in range(len(seq)):
... assert nth_combination(population, r, i) == seq[i]
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
01ebd80b-b004-43d7-8691-7e33ceb2939d | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,052 | supabase-export-v2 | 63ea0cd2615b227f | if stop is None else range(max(start, stop)) next_i = start for i, element in zip(indices, iterable): if i == next_i: yield element next_i += step
If the input is an iterator, then fully consuming the *islice*
advances the input iterator by ``max(start, stop)`` steps regardless
of the *step* value. | trusted_official_docs | CPython Docs | if stop is None else range(max(start, stop)) next_i = start for i, element in zip(indices, iterable): if i == next_i: yield element next_i += step
If the input is an iterator, then fully consuming the *islice*
advances the input iterator by ``max(start, stop)`` steps regardless
of the *step* value. | if stop is None else range(max(start, stop)) next_i = start for i, element in zip(indices, iterable): if i == next_i: yield element next_i += step
If the input is an iterator, then fully consuming the *islice*
advances the input iterator by ``max(start, stop)`` steps regardless
of the *step* value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0254f3f6-4d6e-4c55-b2d5-687f6ccff5af | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,037 | supabase-export-v2 | a69baa2fe2f12540 | groups = [] uniquekeys = [] data = sorted(data, key=keyfunc) for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k)
:func:`groupby` is roughly equivalent to:: | trusted_official_docs | CPython Docs | groups = [] uniquekeys = [] data = sorted(data, key=keyfunc) for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k)
:func:`groupby` is roughly equivalent to:: | groups = [] uniquekeys = [] data = sorted(data, key=keyfunc) for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k)
:func:`groupby` is roughly equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0582c36c-bbc1-4b8a-a9bd-b458c4624fdd | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,213 | supabase-export-v2 | 569989052a404f02 | >>> polynomial_derivative([1, -4, -17, 60]) [3, -8, -17]
>>> list(iter_index('AABCADEAF', 'A'))
[0, 1, 4, 7]
>>> list(iter_index('AABCADEAF', 'B'))
[2]
>>> list(iter_index('AABCADEAF', 'X'))
[]
>>> list(iter_index('', 'X'))
[]
>>> list(iter_index('AABCADEAF', 'A', 1))
[1, 4, 7]
>>> list(iter_index(iter('AABCA... | trusted_official_docs | CPython Docs | >>> polynomial_derivative([1, -4, -17, 60]) [3, -8, -17]
>>> list(iter_index('AABCADEAF', 'A'))
[0, 1, 4, 7]
>>> list(iter_index('AABCADEAF', 'B'))
[2]
>>> list(iter_index('AABCADEAF', 'X'))
[]
>>> list(iter_index('', 'X'))
[]
>>> list(iter_index('AABCADEAF', 'A', 1))
[1, 4, 7]
>>> list(iter_index(iter('AABCA... | >>> polynomial_derivative([1, -4, -17, 60]) [3, -8, -17]
>>> list(iter_index('AABCADEAF', 'A'))
[0, 1, 4, 7]
>>> list(iter_index('AABCADEAF', 'B'))
[2]
>>> list(iter_index('AABCADEAF', 'X'))
[]
>>> list(iter_index('', 'X'))
[]
>>> list(iter_index('AABCADEAF', 'A', 1))
[1, 4, 7]
>>> list(iter_index(iter('AABCA... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0596d8ce-b52b-453c-b7e0-9c350acf971d | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,954 | supabase-export-v2 | 7727e633a8f48f98 | Itertool Functions ------------------
The following functions all construct and return iterators. Some provide
streams of infinite length, so they should only be accessed by functions or
loops that truncate the stream. | trusted_official_docs | CPython Docs | Itertool Functions ------------------
The following functions all construct and return iterators. Some provide
streams of infinite length, so they should only be accessed by functions or
loops that truncate the stream. | Itertool Functions ------------------
The following functions all construct and return iterators. Some provide
streams of infinite length, so they should only be accessed by functions or
loops that truncate the stream. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
06ffb9ac-4bc7-4a43-9b75-e032bdff13a8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,142 | supabase-export-v2 | d7e1759fb5d42ecc | n is None, consume entirely." # Use functions that consume iterators at C speed. if n is None: deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None)
def nth(iterable, n, default=None):
"Returns the nth item or a default value."
return next(islice(iterable, n, None), default) | trusted_official_docs | CPython Docs | n is None, consume entirely." # Use functions that consume iterators at C speed. if n is None: deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None)
def nth(iterable, n, default=None):
"Returns the nth item or a default value."
return next(islice(iterable, n, None), default) | n is None, consume entirely." # Use functions that consume iterators at C speed. if n is None: deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None)
def nth(iterable, n, default=None):
"Returns the nth item or a default value."
return next(islice(iterable, n, None), default) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
07867b48-0023-44c1-a7a1-88a3dcc39c65 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,121 | supabase-export-v2 | c37fb46b0b01d5cd | iterators = list(map(iter, iterables)) num_active = len(iterators) if not num_active: return
while True:
values = []
for i, iterator in enumerate(iterators):
try:
value = next(iterator)
except StopIteration:
num_active -= 1
if not num_active:
return
iterators[i] = repeat(fillvalue)
value = fillvalue
values.a... | trusted_official_docs | CPython Docs | iterators = list(map(iter, iterables)) num_active = len(iterators) if not num_active: return
while True:
values = []
for i, iterator in enumerate(iterators):
try:
value = next(iterator)
except StopIteration:
num_active -= 1
if not num_active:
return
iterators[i] = repeat(fillvalue)
value = fillvalue
values.a... | iterators = list(map(iter, iterables)) num_active = len(iterators) if not num_active: return
while True:
values = []
for i, iterator in enumerate(iterators):
try:
value = next(iterator)
except StopIteration:
num_active -= 1
if not num_active:
return
iterators[i] = repeat(fillvalue)
value = fillvalue
values.a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
08109aa2-f2d2-433c-aec0-6e2e77fc8eb5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,182 | supabase-export-v2 | 24002af847e69764 | def running_mean(iterable): "Average of values seen so far." # running_mean([37, 33, 38, 28]) → 37 35 36 34 return map(truediv, accumulate(iterable), count(1))
def running_min(iterable):
"Smallest of values seen so far."
# running_min([37, 33, 38, 28]) → 37 33 33 28
return accumulate(iterable, func=min) | trusted_official_docs | CPython Docs | def running_mean(iterable): "Average of values seen so far." # running_mean([37, 33, 38, 28]) → 37 35 36 34 return map(truediv, accumulate(iterable), count(1))
def running_min(iterable):
"Smallest of values seen so far."
# running_min([37, 33, 38, 28]) → 37 33 33 28
return accumulate(iterable, func=min) | def running_mean(iterable): "Average of values seen so far." # running_mean([37, 33, 38, 28]) → 37 35 36 34 return map(truediv, accumulate(iterable), count(1))
def running_min(iterable):
"Smallest of values seen so far."
# running_min([37, 33, 38, 28]) → 37 33 33 28
return accumulate(iterable, func=min) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0a510b64-4719-4ba4-b676-f3ea840b2fbe | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,967 | supabase-export-v2 | 1687e935e47eb8df | = lambda balance, payment: round(balance * 1.05) - payment >>> list(accumulate(repeat(90, 10), update, initial=1_000)) [1000, 960, 918, 874, 828, 779, 728, 674, 618, 559, 497]
See :func:`functools.reduce` for a similar function that returns only the
final accumulated value. | trusted_official_docs | CPython Docs | = lambda balance, payment: round(balance * 1.05) - payment >>> list(accumulate(repeat(90, 10), update, initial=1_000)) [1000, 960, 918, 874, 828, 779, 728, 674, 618, 559, 497]
See :func:`functools.reduce` for a similar function that returns only the
final accumulated value. | = lambda balance, payment: round(balance * 1.05) - payment >>> list(accumulate(repeat(90, 10), update, initial=1_000)) [1000, 960, 918, 874, 828, 779, 728, 674, 618, 559, 497]
See :func:`functools.reduce` for a similar function that returns only the
final accumulated value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0dc103a3-6bea-4d47-80a1-41e54cb01df4 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,107 | supabase-export-v2 | 0e0e27662ec987ec | step" allows nested :func:`tee` calls to share the same underlying data chain and to have a single update step rather than a chain of calls.
The flattening property makes tee iterators efficiently peekable: | trusted_official_docs | CPython Docs | step" allows nested :func:`tee` calls to share the same underlying data chain and to have a single update step rather than a chain of calls.
The flattening property makes tee iterators efficiently peekable: | step" allows nested :func:`tee` calls to share the same underlying data chain and to have a single update step rather than a chain of calls.
The flattening property makes tee iterators efficiently peekable: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0eadb32d-3952-4b85-8131-f0011a98620a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,141 | supabase-export-v2 | ff3eccdc966ce18e | def tail(n, iterable): "Return an iterator over the last n items." # tail(3, 'ABCDEFG') → E F G return iter(deque(iterable, maxlen=n))
def consume(iterator, n=None):
"Advance the iterator n-steps ahead. If n is None, consume entirely."
# Use functions that consume iterators at C speed. if n is None:
deque(iterator, ... | trusted_official_docs | CPython Docs | def tail(n, iterable): "Return an iterator over the last n items." # tail(3, 'ABCDEFG') → E F G return iter(deque(iterable, maxlen=n))
def consume(iterator, n=None):
"Advance the iterator n-steps ahead. If n is None, consume entirely."
# Use functions that consume iterators at C speed. if n is None:
deque(iterator, ... | def tail(n, iterable): "Return an iterator over the last n items." # tail(3, 'ABCDEFG') → E F G return iter(deque(iterable, maxlen=n))
def consume(iterator, n=None):
"Advance the iterator n-steps ahead. If n is None, consume entirely."
# Use functions that consume iterators at C speed. if n is None:
deque(iterator, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0ece6af4-ef8d-42ac-8721-00daaba3b37c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,075 | supabase-export-v2 | 6cedb678df0f8e1d | equivalent to nested for-loops in a generator expression. For example, ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
The nested loops cycle like an odometer with the rightmost element advancing
on every iteration. This pattern creates a lexicographic ordering so that if
the input's iterable... | trusted_official_docs | CPython Docs | equivalent to nested for-loops in a generator expression. For example, ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
The nested loops cycle like an odometer with the rightmost element advancing
on every iteration. This pattern creates a lexicographic ordering so that if
the input's iterable... | equivalent to nested for-loops in a generator expression. For example, ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
The nested loops cycle like an odometer with the rightmost element advancing
on every iteration. This pattern creates a lexicographic ordering so that if
the input's iterable... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0f47e602-7416-4284-bf80-2e1d55cc7896 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,122 | supabase-export-v2 | d1cea173ed4b476f | iterator in enumerate(iterators): try: value = next(iterator) except StopIteration: num_active -= 1 if not num_active: return iterators[i] = repeat(fillvalue) value = fillvalue values.append(value) yield tuple(values)
If one of the iterables is potentially infinite, then the :func:`zip_longest`
function should be wrap... | trusted_official_docs | CPython Docs | iterator in enumerate(iterators): try: value = next(iterator) except StopIteration: num_active -= 1 if not num_active: return iterators[i] = repeat(fillvalue) value = fillvalue values.append(value) yield tuple(values)
If one of the iterables is potentially infinite, then the :func:`zip_longest`
function should be wrap... | iterator in enumerate(iterators): try: value = next(iterator) except StopIteration: num_active -= 1 if not num_active: return iterators[i] = repeat(fillvalue) value = fillvalue values.append(value) yield tuple(values)
If one of the iterables is potentially infinite, then the :func:`zip_longest`
function should be wrap... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0faa6c35-0e86-4a38-9b7d-e8f76b8e0fc8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,162 | supabase-export-v2 | b1d0ecacd601a2a6 | # ==== Matrix operations ====
def reshape(matrix, columns):
"Reshape a 2-D matrix to have a given number of columns."
# reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5)
return batched(chain.from_iterable(matrix), columns, strict=True) | trusted_official_docs | CPython Docs | # ==== Matrix operations ====
def reshape(matrix, columns):
"Reshape a 2-D matrix to have a given number of columns."
# reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5)
return batched(chain.from_iterable(matrix), columns, strict=True) | # ==== Matrix operations ====
def reshape(matrix, columns):
"Reshape a 2-D matrix to have a given number of columns."
# reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5)
return batched(chain.from_iterable(matrix), columns, strict=True) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
10a4582f-380e-4703-bfca-8a994a739cce | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,044 | supabase-export-v2 | c77bed92e645da7f | .. function:: islice(iterable, stop) islice(iterable, start, stop[, step])
Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for
*start*, *stop*, or *step*. | trusted_official_docs | CPython Docs | .. function:: islice(iterable, stop) islice(iterable, start, stop[, step])
Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for
*start*, *stop*, or *step*. | .. function:: islice(iterable, stop) islice(iterable, start, stop[, step])
Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for
*start*, *stop*, or *step*. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
13edbdc3-6c3f-4e7c-8c6b-ccf93ee63908 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,078 | supabase-export-v2 | fe20b93eb61e374a | This function is roughly equivalent to the following code, except that the actual implementation does not build up intermediate results in memory::
def product(*iterables, repeat=1):
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) → 000 001 010 011 100 101 110 111 | trusted_official_docs | CPython Docs | This function is roughly equivalent to the following code, except that the actual implementation does not build up intermediate results in memory::
def product(*iterables, repeat=1):
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) → 000 001 010 011 100 101 110 111 | This function is roughly equivalent to the following code, except that the actual implementation does not build up intermediate results in memory::
def product(*iterables, repeat=1):
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) → 000 001 010 011 100 101 110 111 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
15cbd1ae-fd28-4196-9654-03281a82f414 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,139 | supabase-export-v2 | 722802bce72a58af | def ncycles(iterable, n): "Returns the sequence elements n times." return chain.from_iterable(repeat(tuple(iterable), n))
def loops(n):
"Loop n times. Like range(n) but without creating integers."
# for _ in loops(100): ... return repeat(None, n) | trusted_official_docs | CPython Docs | def ncycles(iterable, n): "Returns the sequence elements n times." return chain.from_iterable(repeat(tuple(iterable), n))
def loops(n):
"Loop n times. Like range(n) but without creating integers."
# for _ in loops(100): ... return repeat(None, n) | def ncycles(iterable, n): "Returns the sequence elements n times." return chain.from_iterable(repeat(tuple(iterable), n))
def loops(n):
"Loop n times. Like range(n) but without creating integers."
# for _ in loops(100): ... return repeat(None, n) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
17e3ef18-1104-4be9-8886-e608aab99c82 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,050 | supabase-export-v2 | dd8b5711f52e95d9 | 2, 4) → C D # islice('ABCDEFG', 2, None) → C D E F G # islice('ABCDEFG', 0, None, 2) → A C E G
s = slice(*args)
start = 0 if s.start is None else s.start
stop = s.stop
step = 1 if s.step is None else s.step
if start < 0 or (stop is not None and stop < 0) or step <= 0:
raise ValueError | trusted_official_docs | CPython Docs | 2, 4) → C D # islice('ABCDEFG', 2, None) → C D E F G # islice('ABCDEFG', 0, None, 2) → A C E G
s = slice(*args)
start = 0 if s.start is None else s.start
stop = s.stop
step = 1 if s.step is None else s.step
if start < 0 or (stop is not None and stop < 0) or step <= 0:
raise ValueError | 2, 4) → C D # islice('ABCDEFG', 2, None) → C D E F G # islice('ABCDEFG', 0, None, 2) → A C E G
s = slice(*args)
start = 0 if s.start is None else s.start
stop = s.stop
step = 1 if s.step is None else s.step
if start < 0 or (stop is not None and stop < 0) or step <= 0:
raise ValueError | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1ac59a22-0414-42aa-bb12-ea8ed27c3396 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,224 | supabase-export-v2 | 21d6ae47e8063b94 | >>> list(grouper('abcdefg', 3, fillvalue='x')) [('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]
>>> it = grouper('abcdefg', 3, incomplete='strict')
>>> next(it)
('a', 'b', 'c')
>>> next(it)
('d', 'e', 'f')
>>> next(it)
Traceback (most recent call last):
... ValueError: zip() argument 2 is shorter than argumen... | trusted_official_docs | CPython Docs | >>> list(grouper('abcdefg', 3, fillvalue='x')) [('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]
>>> it = grouper('abcdefg', 3, incomplete='strict')
>>> next(it)
('a', 'b', 'c')
>>> next(it)
('d', 'e', 'f')
>>> next(it)
Traceback (most recent call last):
... ValueError: zip() argument 2 is shorter than argumen... | >>> list(grouper('abcdefg', 3, fillvalue='x')) [('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]
>>> it = grouper('abcdefg', 3, incomplete='strict')
>>> next(it)
('a', 'b', 'c')
>>> next(it)
('d', 'e', 'f')
>>> next(it)
Traceback (most recent call last):
... ValueError: zip() argument 2 is shorter than argumen... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1b8847de-4bb7-43f8-9c3e-d8a1f520eab0 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,153 | supabase-export-v2 | dc8c17bc88006de6 | C # Algorithm credited to George Sakkis iterators = map(iter, iterables) for num_active in range(len(iterables), 0, -1): iterators = cycle(islice(iterators, num_active)) yield from map(next, iterators)
def subslices(seq):
"Return all contiguous non-empty subslices of a sequence."
# subslices('ABCD') → A AB ABC ABCD B... | trusted_official_docs | CPython Docs | C # Algorithm credited to George Sakkis iterators = map(iter, iterables) for num_active in range(len(iterables), 0, -1): iterators = cycle(islice(iterators, num_active)) yield from map(next, iterators)
def subslices(seq):
"Return all contiguous non-empty subslices of a sequence."
# subslices('ABCD') → A AB ABC ABCD B... | C # Algorithm credited to George Sakkis iterators = map(iter, iterables) for num_active in range(len(iterables), 0, -1): iterators = cycle(islice(iterators, num_active)) yield from map(next, iterators)
def subslices(seq):
"Return all contiguous non-empty subslices of a sequence."
# subslices('ABCD') → A AB ABC ABCD B... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c763f9e-b43b-4f01-a9c1-082e6ce825b4 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,150 | supabase-export-v2 | 16f2a2fc533e737a | sorted order. Supports unhashable inputs." # unique([[1, 2], [3, 4], [1, 2]]) → [1, 2] [3, 4] sequenced = sorted(iterable, key=key, reverse=reverse) return unique_justseen(sequenced, key=key)
def sliding_window(iterable, n):
"Collect data into overlapping fixed-length chunks or blocks."
# sliding_window('ABCDEFG', 3)... | trusted_official_docs | CPython Docs | sorted order. Supports unhashable inputs." # unique([[1, 2], [3, 4], [1, 2]]) → [1, 2] [3, 4] sequenced = sorted(iterable, key=key, reverse=reverse) return unique_justseen(sequenced, key=key)
def sliding_window(iterable, n):
"Collect data into overlapping fixed-length chunks or blocks."
# sliding_window('ABCDEFG', 3)... | sorted order. Supports unhashable inputs." # unique([[1, 2], [3, 4], [1, 2]]) → [1, 2] [3, 4] sequenced = sorted(iterable, key=key, reverse=reverse) return unique_justseen(sequenced, key=key)
def sliding_window(iterable, n):
"Collect data into overlapping fixed-length chunks or blocks."
# sliding_window('ABCDEFG', 3)... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d414a52-1654-4bad-8d3a-8229a39df9be | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,212 | supabase-export-v2 | 60281910354f7e71 | 4) * (x - 3) >>> expanded = lambda x: x**3 -4*x**2 -17*x + 60 >>> all(factored(x) == expanded(x) for x in range(-10, 11)) True
>>> polynomial_derivative([1, -4, -17, 60])
[3, -8, -17] | trusted_official_docs | CPython Docs | 4) * (x - 3) >>> expanded = lambda x: x**3 -4*x**2 -17*x + 60 >>> all(factored(x) == expanded(x) for x in range(-10, 11)) True
>>> polynomial_derivative([1, -4, -17, 60])
[3, -8, -17] | 4) * (x - 3) >>> expanded = lambda x: x**3 -4*x**2 -17*x + 60 >>> all(factored(x) == expanded(x) for x in range(-10, 11)) True
>>> polynomial_derivative([1, -4, -17, 60])
[3, -8, -17] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1f08e7a8-63f8-407c-a87c-d9a1b5aef97e | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,169 | supabase-export-v2 | 38b3571ed5a4293b | → 2nd derivative estimate kernel = tuple(kernel)[::-1] n = len(kernel) padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1)) windowed_signal = sliding_window(padded_signal, n) return map(sumprod, repeat(kernel), windowed_signal)
def polynomial_from_roots(roots):
"""Compute a polynomial's coefficients from its ... | trusted_official_docs | CPython Docs | → 2nd derivative estimate kernel = tuple(kernel)[::-1] n = len(kernel) padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1)) windowed_signal = sliding_window(padded_signal, n) return map(sumprod, repeat(kernel), windowed_signal)
def polynomial_from_roots(roots):
"""Compute a polynomial's coefficients from its ... | → 2nd derivative estimate kernel = tuple(kernel)[::-1] n = len(kernel) padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1)) windowed_signal = sliding_window(padded_signal, n) return map(sumprod, repeat(kernel), windowed_signal)
def polynomial_from_roots(roots):
"""Compute a polynomial's coefficients from its ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1f621079-54b4-4c51-966a-d29127c0461f | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,188 | supabase-export-v2 | a7ad841e228e02cd | These examples no longer appear in the docs but are guaranteed to keep working.
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in zip(count(1200), amounts):
... print('Check %d is for $%.2f' % (checknum, amount))
... Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14 | trusted_official_docs | CPython Docs | These examples no longer appear in the docs but are guaranteed to keep working.
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in zip(count(1200), amounts):
... print('Check %d is for $%.2f' % (checknum, amount))
... Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14 | These examples no longer appear in the docs but are guaranteed to keep working.
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in zip(count(1200), amounts):
... print('Check %d is for $%.2f' % (checknum, amount))
... Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
204e49dc-ed87-498a-9b25-9a489af34956 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,999 | supabase-export-v2 | 9e1b453e04a39b12 | elements) of the *iterable*. The number of subsequence returned is ``(n + r - 1)! / r! / (n - 1)!`` when ``n > 0``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. if the input *iterable* is sorted,
the output tuples will be produced in sorted order. | trusted_official_docs | CPython Docs | elements) of the *iterable*. The number of subsequence returned is ``(n + r - 1)! / r! / (n - 1)!`` when ``n > 0``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. if the input *iterable* is sorted,
the output tuples will be produced in sorted order. | elements) of the *iterable*. The number of subsequence returned is ``(n + r - 1)! / r! / (n - 1)!`` when ``n > 0``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. if the input *iterable* is sorted,
the output tuples will be produced in sorted order. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
20a9eeaf-81dc-4c7a-ba1d-736312cd7f10 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,960 | supabase-export-v2 | 00cec0d4661727ba | Roughly equivalent to::
def accumulate(iterable, function=operator.add, *, initial=None):
'Return running totals'
# accumulate([1,2,3,4,5]) → 1 3 6 10 15
# accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115
# accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120 | trusted_official_docs | CPython Docs | Roughly equivalent to::
def accumulate(iterable, function=operator.add, *, initial=None):
'Return running totals'
# accumulate([1,2,3,4,5]) → 1 3 6 10 15
# accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115
# accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120 | Roughly equivalent to::
def accumulate(iterable, function=operator.add, *, initial=None):
'Return running totals'
# accumulate([1,2,3,4,5]) → 1 3 6 10 15
# accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115
# accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
21c07caa-f026-4e00-843f-589a2bf5996d | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,998 | supabase-export-v2 | 2b35d700cef4fb1b | Return *r* length subsequences of elements from the input *iterable* allowing individual elements to be repeated more than once.
The output is a subsequence of :func:`product` that keeps only entries
that are subsequences (with possible repeated elements) of the
*iterable*. The number of subsequence returned is ``(n ... | trusted_official_docs | CPython Docs | Return *r* length subsequences of elements from the input *iterable* allowing individual elements to be repeated more than once.
The output is a subsequence of :func:`product` that keeps only entries
that are subsequences (with possible repeated elements) of the
*iterable*. The number of subsequence returned is ``(n ... | Return *r* length subsequences of elements from the input *iterable* allowing individual elements to be repeated more than once.
The output is a subsequence of :func:`product` that keeps only entries
that are subsequences (with possible repeated elements) of the
*iterable*. The number of subsequence returned is ``(n ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
228354f0-1313-4cc2-928c-4c7b91d94870 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,251 | supabase-export-v2 | 168b49e6076ff093 | "Return overlapping triplets from an iterable" # triplewise('ABCDEFG') → ABC BCD CDE DEF EFG for (a, _), (b, c) in pairwise(pairwise(iterable)): yield a, b, c
def nth_combination(iterable, r, index):
"Equivalent to list(combinations(iterable, r))[index]"
pool = tuple(iterable)
n = len(pool)
c = math.comb(n, r)
if ... | trusted_official_docs | CPython Docs | "Return overlapping triplets from an iterable" # triplewise('ABCDEFG') → ABC BCD CDE DEF EFG for (a, _), (b, c) in pairwise(pairwise(iterable)): yield a, b, c
def nth_combination(iterable, r, index):
"Equivalent to list(combinations(iterable, r))[index]"
pool = tuple(iterable)
n = len(pool)
c = math.comb(n, r)
if ... | "Return overlapping triplets from an iterable" # triplewise('ABCDEFG') → ABC BCD CDE DEF EFG for (a, _), (b, c) in pairwise(pairwise(iterable)): yield a, b, c
def nth_combination(iterable, r, index):
"Equivalent to list(combinations(iterable, r))[index]"
pool = tuple(iterable)
n = len(pool)
c = math.comb(n, r)
if ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
22be74ff-4e80-4139-875a-80c5cbbc9611 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,214 | supabase-export-v2 | 8d3def85d354f718 | # Verify that ValueErrors not swallowed (gh-107208) >>> def assert_no_value(iterable, forbidden_value): ... for item in iterable: ... if item == forbidden_value: ... raise ValueError ...
yield item
... >>> list(iter_index(assert_no_value('AABCADEAF', 'B'), 'A'))
Traceback (most recent call last):
... ValueError
>>>... | trusted_official_docs | CPython Docs | # Verify that ValueErrors not swallowed (gh-107208) >>> def assert_no_value(iterable, forbidden_value): ... for item in iterable: ... if item == forbidden_value: ... raise ValueError ...
yield item
... >>> list(iter_index(assert_no_value('AABCADEAF', 'B'), 'A'))
Traceback (most recent call last):
... ValueError
>>>... | # Verify that ValueErrors not swallowed (gh-107208) >>> def assert_no_value(iterable, forbidden_value): ... for item in iterable: ... if item == forbidden_value: ... raise ValueError ...
yield item
... >>> list(iter_index(assert_no_value('AABCADEAF', 'B'), 'A'))
Traceback (most recent call last):
... ValueError
>>>... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
23cf28c7-3208-4aee-85ff-ddbc52e09a56 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,049 | supabase-export-v2 | 1bd1053d30de969b | Roughly equivalent to::
def islice(iterable, *args):
# islice('ABCDEFG', 2) → A B
# islice('ABCDEFG', 2, 4) → C D
# islice('ABCDEFG', 2, None) → C D E F G
# islice('ABCDEFG', 0, None, 2) → A C E G | trusted_official_docs | CPython Docs | Roughly equivalent to::
def islice(iterable, *args):
# islice('ABCDEFG', 2) → A B
# islice('ABCDEFG', 2, 4) → C D
# islice('ABCDEFG', 2, None) → C D E F G
# islice('ABCDEFG', 0, None, 2) → A C E G | Roughly equivalent to::
def islice(iterable, *args):
# islice('ABCDEFG', 2) → A B
# islice('ABCDEFG', 2, 4) → C D
# islice('ABCDEFG', 2, None) → C D E F G
# islice('ABCDEFG', 0, None, 2) → A C E G | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
261aa419-ba2c-4f9f-b8dc-3c1fe37050ad | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,242 | supabase-export-v2 | 8a125be7b1f1d6ff | >>> list(running_median([37, 33, 38, 28])) [37, 35.0, 37, 35.0]
>>> list(running_statistics([37, 33, 38, 28]))
[(1, 37, 37, 37, 37.0), (2, 33, 35.0, 37, 35.0), (3, 33, 37, 38, 36.0), (4, 28, 35.0, 38, 34.0)] | trusted_official_docs | CPython Docs | >>> list(running_median([37, 33, 38, 28])) [37, 35.0, 37, 35.0]
>>> list(running_statistics([37, 33, 38, 28]))
[(1, 37, 37, 37, 37.0), (2, 33, 35.0, 37, 35.0), (3, 33, 37, 38, 36.0), (4, 28, 35.0, 38, 34.0)] | >>> list(running_median([37, 33, 38, 28])) [37, 35.0, 37, 35.0]
>>> list(running_statistics([37, 33, 38, 28]))
[(1, 37, 37, 37, 37.0), (2, 33, 35.0, 37, 35.0), (3, 33, 37, 38, 36.0), (4, 28, 35.0, 38, 34.0)] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
26262581-aab7-4302-886d-fe7eb7fa5704 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,146 | supabase-export-v2 | b6a2985f97ac5e43 | def all_equal(iterable, key=None): "Returns True if all the elements are equal to each other." # all_equal('4٤௪౪໔', key=int) → True return len(take(2, groupby(iterable, key))) <= 1
# ==== Data pipelines ==== | trusted_official_docs | CPython Docs | def all_equal(iterable, key=None): "Returns True if all the elements are equal to each other." # all_equal('4٤௪౪໔', key=int) → True return len(take(2, groupby(iterable, key))) <= 1
# ==== Data pipelines ==== | def all_equal(iterable, key=None): "Returns True if all the elements are equal to each other." # all_equal('4٤௪౪໔', key=int) → True return len(take(2, groupby(iterable, key))) <= 1
# ==== Data pipelines ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
264a82c1-ece4-4f01-8194-9c161061825c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,950 | supabase-export-v2 | 835e3d4e89088daf | ============================================== ==================== ============================================================= Iterator Arguments Results ============================================== ==================== ============================================================= :func:`product` p, q, ...
[repeat... | trusted_official_docs | CPython Docs | ============================================== ==================== ============================================================= Iterator Arguments Results ============================================== ==================== ============================================================= :func:`product` p, q, ...
[repeat... | ============================================== ==================== ============================================================= Iterator Arguments Results ============================================== ==================== ============================================================= :func:`product` p, q, ...
[repeat... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
27b3b86d-46ea-4471-b5e3-8bef3422b8b8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,217 | supabase-export-v2 | d9e5c2523ea2e8ce | that do not match the general behavior specified >>> # in collections.abc.Sequence.index(). >>> seq = 'abracadabra' >>> target = 'ab' >>> list(iter_index(seq, target)) [0, 7]
>>> list(sieve(30))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61... | trusted_official_docs | CPython Docs | that do not match the general behavior specified >>> # in collections.abc.Sequence.index(). >>> seq = 'abracadabra' >>> target = 'ab' >>> list(iter_index(seq, target)) [0, 7]
>>> list(sieve(30))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61... | that do not match the general behavior specified >>> # in collections.abc.Sequence.index(). >>> seq = 'abracadabra' >>> target = 'ab' >>> list(iter_index(seq, target)) [0, 7]
>>> list(sieve(30))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2927567b-84b6-478b-a253-ae30eb406423 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,974 | supabase-export-v2 | 469a9c15fef1de0c | If *strict* is true, will raise a :exc:`ValueError` if the final batch is shorter than *n*.
Loops over the input iterable and accumulates data into tuples up to
size *n*. The input is consumed lazily, just enough to fill a batch. The result is yielded as soon as the batch is full or when the input
iterable is exhaust... | trusted_official_docs | CPython Docs | If *strict* is true, will raise a :exc:`ValueError` if the final batch is shorter than *n*.
Loops over the input iterable and accumulates data into tuples up to
size *n*. The input is consumed lazily, just enough to fill a batch. The result is yielded as soon as the batch is full or when the input
iterable is exhaust... | If *strict* is true, will raise a :exc:`ValueError` if the final batch is shorter than *n*.
Loops over the input iterable and accumulates data into tuples up to
size *n*. The input is consumed lazily, just enough to fill a batch. The result is yielded as soon as the batch is full or when the input
iterable is exhaust... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2ab0d597-ff59-4333-9a35-547e0d703ba2 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,994 | supabase-export-v2 | a7ec18e91cca0393 | def combinations(iterable, r): # combinations('ABCD', 2) → AB AC AD BC BD CD # combinations(range(4), 3) → 012 013 023 123
pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = list(range(r)) | trusted_official_docs | CPython Docs | def combinations(iterable, r): # combinations('ABCD', 2) → AB AC AD BC BD CD # combinations(range(4), 3) → 012 013 023 123
pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = list(range(r)) | def combinations(iterable, r): # combinations('ABCD', 2) → AB AC AD BC BD CD # combinations(range(4), 3) → 012 013 023 123
pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = list(range(r)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b0c972f-700e-432f-ad76-4523f716ea70 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,165 | supabase-export-v2 | d8ebeb99cac88f67 | "Multiply two matrices." # matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60) n = len(m2[0]) return batched(starmap(sumprod, product(m1, transpose(m2))), n)
# ==== Polynomial arithmetic ==== | trusted_official_docs | CPython Docs | "Multiply two matrices." # matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60) n = len(m2[0]) return batched(starmap(sumprod, product(m1, transpose(m2))), n)
# ==== Polynomial arithmetic ==== | "Multiply two matrices." # matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60) n = len(m2[0]) return batched(starmap(sumprod, product(m1, transpose(m2))), n)
# ==== Polynomial arithmetic ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2bc60d8f-57da-40c0-8389-2e6304567b11 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,184 | supabase-export-v2 | 1c3959aaeb7a5cdc | def running_max(iterable): "Largest of values seen so far." # running_max([37, 33, 38, 28]) → 37 37 38 38 return accumulate(iterable, func=max)
def running_median(iterable):
"Median of values seen so far."
# running_median([37, 33, 38, 28]) → 37 35 37 35
read = iter(iterable).__next__
lo = [] # max-heap
hi = [] # ... | trusted_official_docs | CPython Docs | def running_max(iterable): "Largest of values seen so far." # running_max([37, 33, 38, 28]) → 37 37 38 38 return accumulate(iterable, func=max)
def running_median(iterable):
"Median of values seen so far."
# running_median([37, 33, 38, 28]) → 37 35 37 35
read = iter(iterable).__next__
lo = [] # max-heap
hi = [] # ... | def running_max(iterable): "Largest of values seen so far." # running_max([37, 33, 38, 28]) → 37 37 38 38 return accumulate(iterable, func=max)
def running_median(iterable):
"Median of values seen so far."
# running_median([37, 33, 38, 28]) → 37 35 37 35
read = iter(iterable).__next__
lo = [] # max-heap
hi = [] # ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2bf89e46-9145-49d3-8465-f12a9a2ae983 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,175 | supabase-export-v2 | 829824738d363034 | = 3x² -8x -17 """ # polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17] n = len(coefficients) powers = reversed(range(1, n)) return list(map(mul, coefficients, powers))
# ==== Number theory ==== | trusted_official_docs | CPython Docs | = 3x² -8x -17 """ # polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17] n = len(coefficients) powers = reversed(range(1, n)) return list(map(mul, coefficients, powers))
# ==== Number theory ==== | = 3x² -8x -17 """ # polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17] n = len(coefficients) powers = reversed(range(1, n)) return list(map(mul, coefficients, powers))
# ==== Number theory ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2f7757d6-f5c1-45af-af2e-42f8b1d8b041 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,220 | supabase-export-v2 | 306e9723324913ca | n for n in range(1, 2_000)) True >>> all(set(factor(n)) <= set(sieve(n+1)) for n in range(2_000)) True >>> all(list(factor(n)) == sorted(factor(n)) for n in range(2_000)) True
>>> totient(0) # https://www.wolframalpha.com/input?i=totient+0
0
>>> first_totients = [1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, ... | trusted_official_docs | CPython Docs | n for n in range(1, 2_000)) True >>> all(set(factor(n)) <= set(sieve(n+1)) for n in range(2_000)) True >>> all(list(factor(n)) == sorted(factor(n)) for n in range(2_000)) True
>>> totient(0) # https://www.wolframalpha.com/input?i=totient+0
0
>>> first_totients = [1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, ... | n for n in range(1, 2_000)) True >>> all(set(factor(n)) <= set(sieve(n+1)) for n in range(2_000)) True >>> all(list(factor(n)) == sorted(factor(n)) for n in range(2_000)) True
>>> totient(0) # https://www.wolframalpha.com/input?i=totient+0
0
>>> first_totients = [1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3004854e-0d8c-49a4-a1c6-11c2d13e8f5c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,036 | supabase-export-v2 | ee4d3dd300cb9851 | :func:`groupby` object is advanced, the previous group is no longer visible. So, if that data is needed later, it should be stored as a list::
groups = []
uniquekeys = []
data = sorted(data, key=keyfunc)
for k, g in groupby(data, keyfunc):
groups.append(list(g)) # Store group iterator as a list
uniquekeys.append(k... | trusted_official_docs | CPython Docs | :func:`groupby` object is advanced, the previous group is no longer visible. So, if that data is needed later, it should be stored as a list::
groups = []
uniquekeys = []
data = sorted(data, key=keyfunc)
for k, g in groupby(data, keyfunc):
groups.append(list(g)) # Store group iterator as a list
uniquekeys.append(k... | :func:`groupby` object is advanced, the previous group is no longer visible. So, if that data is needed later, it should be stored as a list::
groups = []
uniquekeys = []
data = sorted(data, key=keyfunc)
for k, g in groupby(data, keyfunc):
groups.append(list(g)) # Store group iterator as a list
uniquekeys.append(k... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
35e91ddf-578f-44ec-b91e-5bca9f77bcbd | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,127 | supabase-export-v2 | 3b31cbffdd05a8d3 | show patterns for using itertools with the :mod:`operator` and :mod:`collections` modules as well as with the built-in itertools such as ``map()``, ``filter()``, ``reversed()``, and ``enumerate()``.
A secondary purpose of the recipes is to serve as an incubator. The
``accumulate()``, ``compress()``, and ``pairwise()`` ... | trusted_official_docs | CPython Docs | show patterns for using itertools with the :mod:`operator` and :mod:`collections` modules as well as with the built-in itertools such as ``map()``, ``filter()``, ``reversed()``, and ``enumerate()``.
A secondary purpose of the recipes is to serve as an incubator. The
``accumulate()``, ``compress()``, and ``pairwise()`` ... | show patterns for using itertools with the :mod:`operator` and :mod:`collections` modules as well as with the built-in itertools such as ``map()``, ``filter()``, ``reversed()``, and ``enumerate()``.
A secondary purpose of the recipes is to serve as an incubator. The
``accumulate()``, ``compress()``, and ``pairwise()`` ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
35ec9081-69ac-433f-aa25-694f77298d7a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,016 | supabase-export-v2 | b4faaf0fed8532b2 | .. function:: cycle(iterable)
Make an iterator returning elements from the *iterable* and saving a
copy of each. When the iterable is exhausted, return elements from
the saved copy. Repeats indefinitely. Roughly equivalent to:: | trusted_official_docs | CPython Docs | .. function:: cycle(iterable)
Make an iterator returning elements from the *iterable* and saving a
copy of each. When the iterable is exhausted, return elements from
the saved copy. Repeats indefinitely. Roughly equivalent to:: | .. function:: cycle(iterable)
Make an iterator returning elements from the *iterable* and saving a
copy of each. When the iterable is exhausted, return elements from
the saved copy. Repeats indefinitely. Roughly equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
366ec880-6636-4068-8a8a-566c20bbd529 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,013 | supabase-export-v2 | 77f96d8a3c8eccd7 | → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start while True: yield n n += step
When counting with floating-point numbers, better accuracy can sometimes be
achieved by substituting multiplicative code such as: ``(start + step * i
for i in count())``. | trusted_official_docs | CPython Docs | → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start while True: yield n n += step
When counting with floating-point numbers, better accuracy can sometimes be
achieved by substituting multiplicative code such as: ``(start + step * i
for i in count())``. | → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start while True: yield n n += step
When counting with floating-point numbers, better accuracy can sometimes be
achieved by substituting multiplicative code such as: ``(start + step * i
for i in count())``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
376eb107-1509-4754-8a7d-64871eb83de6 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,055 | supabase-export-v2 | 8286d76d26420574 | Return successive overlapping pairs taken from the input *iterable*.
The number of 2-tuples in the output iterator will be one fewer than the
number of inputs. It will be empty if the input iterable has fewer than
two values. | trusted_official_docs | CPython Docs | Return successive overlapping pairs taken from the input *iterable*.
The number of 2-tuples in the output iterator will be one fewer than the
number of inputs. It will be empty if the input iterable has fewer than
two values. | Return successive overlapping pairs taken from the input *iterable*.
The number of 2-tuples in the output iterator will be one fewer than the
number of inputs. It will be empty if the input iterable has fewer than
two values. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
378c7d44-e9fd-4bad-ba27-3517544bf5c1 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,097 | supabase-export-v2 | 8547c0db312beab5 | def takewhile(predicate, iterable): # takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4 for x in iterable: if not predicate(x): break yield x
Note, the element that first fails the predicate condition is
consumed from the input iterator and there is no way to access it. This could be an issue if an application wants to furt... | trusted_official_docs | CPython Docs | def takewhile(predicate, iterable): # takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4 for x in iterable: if not predicate(x): break yield x
Note, the element that first fails the predicate condition is
consumed from the input iterator and there is no way to access it. This could be an issue if an application wants to furt... | def takewhile(predicate, iterable): # takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4 for x in iterable: if not predicate(x): break yield x
Note, the element that first fails the predicate condition is
consumed from the input iterator and there is no way to access it. This could be an issue if an application wants to furt... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
39305ff8-1d2f-4d47-b297-07472545d1c1 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,111 | supabase-export-v2 | 8504ba709b11e7ff | .. doctest::
>>> iterator = iter('abcdef')
>>> [iterator] = tee(iterator, 1) # Make the input peekable
>>> next(iterator) # Move the iterator forward
'a'
>>> lookahead(iterator) # Check next value
'b'
>>> next(iterator) # Continue moving forward
'b' | trusted_official_docs | CPython Docs | .. doctest::
>>> iterator = iter('abcdef')
>>> [iterator] = tee(iterator, 1) # Make the input peekable
>>> next(iterator) # Move the iterator forward
'a'
>>> lookahead(iterator) # Check next value
'b'
>>> next(iterator) # Continue moving forward
'b' | .. doctest::
>>> iterator = iter('abcdef')
>>> [iterator] = tee(iterator, 1) # Make the input peekable
>>> next(iterator) # Move the iterator forward
'a'
>>> lookahead(iterator) # Check next value
'b'
>>> next(iterator) # Continue moving forward
'b' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3aa80420-3c1f-4c99-90b2-25a78fd1f266 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,051 | supabase-export-v2 | bdfb187aa8385799 | if s.step is None else s.step if start < 0 or (stop is not None and stop < 0) or step <= 0: raise ValueError
indices = count() if stop is None else range(max(start, stop))
next_i = start
for i, element in zip(indices, iterable):
if i == next_i:
yield element
next_i += step | trusted_official_docs | CPython Docs | if s.step is None else s.step if start < 0 or (stop is not None and stop < 0) or step <= 0: raise ValueError
indices = count() if stop is None else range(max(start, stop))
next_i = start
for i, element in zip(indices, iterable):
if i == next_i:
yield element
next_i += step | if s.step is None else s.step if start < 0 or (stop is not None and stop < 0) or step <= 0: raise ValueError
indices = count() if stop is None else range(max(start, stop))
next_i = start
for i, element in zip(indices, iterable):
if i == next_i:
yield element
next_i += step | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3be9b28a-171d-4de9-b945-6b03eb3f1982 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,168 | supabase-export-v2 | 6bcd315f100a413e | commutative; however, the inputs are evaluated differently. The signal is consumed lazily and can be infinite. The kernel is fully consumed before the calculations begin.
Article: https://betterexplained.com/articles/intuitive-convolution/
Video: https://www.youtube.com/watch?v=KuXjwB4LzSA
"""
# convolve([1, -1, -20... | trusted_official_docs | CPython Docs | commutative; however, the inputs are evaluated differently. The signal is consumed lazily and can be infinite. The kernel is fully consumed before the calculations begin.
Article: https://betterexplained.com/articles/intuitive-convolution/
Video: https://www.youtube.com/watch?v=KuXjwB4LzSA
"""
# convolve([1, -1, -20... | commutative; however, the inputs are evaluated differently. The signal is consumed lazily and can be infinite. The kernel is fully consumed before the calculations begin.
Article: https://betterexplained.com/articles/intuitive-convolution/
Video: https://www.youtube.com/watch?v=KuXjwB4LzSA
"""
# convolve([1, -1, -20... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3c1f7011-b2cd-426a-b66c-cbdef0e0e316 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,038 | supabase-export-v2 | fee913de950fdfc0 | :func:`groupby` is roughly equivalent to::
def groupby(iterable, key=None):
# [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B
# [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D | trusted_official_docs | CPython Docs | :func:`groupby` is roughly equivalent to::
def groupby(iterable, key=None):
# [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B
# [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D | :func:`groupby` is roughly equivalent to::
def groupby(iterable, key=None):
# [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B
# [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3c596bb8-218d-4255-8b27-fcdabdb28ecc | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,941 | supabase-export-v2 | eee8625bd3b33c0f | implements a number of :term:`iterator` building blocks inspired by constructs from APL, Haskell, and SML. Each has been recast in a form suitable for Python.
The module standardizes a core set of fast, memory efficient tools that are
useful by themselves or in combination. Together, they form an "iterator
algebra" mak... | trusted_official_docs | CPython Docs | implements a number of :term:`iterator` building blocks inspired by constructs from APL, Haskell, and SML. Each has been recast in a form suitable for Python.
The module standardizes a core set of fast, memory efficient tools that are
useful by themselves or in combination. Together, they form an "iterator
algebra" mak... | implements a number of :term:`iterator` building blocks inspired by constructs from APL, Haskell, and SML. Each has been recast in a form suitable for Python.
The module standardizes a core set of fast, memory efficient tools that are
useful by themselves or in combination. Together, they form an "iterator
algebra" mak... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
40705e22-6376-4050-9d90-3edddbb7227a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,183 | supabase-export-v2 | b18a1e6de095ebb8 | def running_min(iterable): "Smallest of values seen so far." # running_min([37, 33, 38, 28]) → 37 33 33 28 return accumulate(iterable, func=min)
def running_max(iterable):
"Largest of values seen so far."
# running_max([37, 33, 38, 28]) → 37 37 38 38
return accumulate(iterable, func=max) | trusted_official_docs | CPython Docs | def running_min(iterable): "Smallest of values seen so far." # running_min([37, 33, 38, 28]) → 37 33 33 28 return accumulate(iterable, func=min)
def running_max(iterable):
"Largest of values seen so far."
# running_max([37, 33, 38, 28]) → 37 37 38 38
return accumulate(iterable, func=max) | def running_min(iterable): "Smallest of values seen so far." # running_min([37, 33, 38, 28]) → 37 33 33 28 return accumulate(iterable, func=min)
def running_max(iterable):
"Largest of values seen so far."
# running_max([37, 33, 38, 28]) → 37 37 38 38
return accumulate(iterable, func=max) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
40f7d0fb-399a-4d20-8983-7f048c5f6504 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,070 | supabase-export-v2 | 57c5746bcf18c22e | pool = tuple(iterable) n = len(pool) r = n if r is None else r if r > n: return
indices = list(range(n))
cycles = list(range(n, n-r, -1))
yield tuple(pool[i] for i in indices[:r]) | trusted_official_docs | CPython Docs | pool = tuple(iterable) n = len(pool) r = n if r is None else r if r > n: return
indices = list(range(n))
cycles = list(range(n, n-r, -1))
yield tuple(pool[i] for i in indices[:r]) | pool = tuple(iterable) n = len(pool) r = n if r is None else r if r > n: return
indices = list(range(n))
cycles = list(range(n, n-r, -1))
yield tuple(pool[i] for i in indices[:r]) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
436f092d-5c05-44f7-a9a8-e54fdc980b0a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,258 | supabase-export-v2 | 4638869ea2455c1a | def partition(predicate, iterable): """Partition entries into false entries and true entries.
If *predicate* is slow, consider wrapping it with functools.lru_cache(). """
# partition(is_odd, range(10)) → 0 2 4 6 8 and 1 3 5 7 9
t1, t2 = tee(iterable)
return filterfalse(predicate, t1), filter(predicate, t2) | trusted_official_docs | CPython Docs | def partition(predicate, iterable): """Partition entries into false entries and true entries.
If *predicate* is slow, consider wrapping it with functools.lru_cache(). """
# partition(is_odd, range(10)) → 0 2 4 6 8 and 1 3 5 7 9
t1, t2 = tee(iterable)
return filterfalse(predicate, t1), filter(predicate, t2) | def partition(predicate, iterable): """Partition entries into false entries and true entries.
If *predicate* is slow, consider wrapping it with functools.lru_cache(). """
# partition(is_odd, range(10)) → 0 2 4 6 8 and 1 3 5 7 9
t1, t2 = tee(iterable)
return filterfalse(predicate, t1), filter(predicate, t2) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
43bcd97f-d7a2-4f64-a51e-ad297e0c90b3 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,112 | supabase-export-v2 | 991cb3f1c52f9f85 | the input peekable >>> next(iterator) # Move the iterator forward 'a' >>> lookahead(iterator) # Check next value 'b' >>> next(iterator) # Continue moving forward 'b'
``tee`` iterators are not threadsafe. A :exc:`RuntimeError` may be
raised when simultaneously using iterators returned by the same :func:`tee`
call, eve... | trusted_official_docs | CPython Docs | the input peekable >>> next(iterator) # Move the iterator forward 'a' >>> lookahead(iterator) # Check next value 'b' >>> next(iterator) # Continue moving forward 'b'
``tee`` iterators are not threadsafe. A :exc:`RuntimeError` may be
raised when simultaneously using iterators returned by the same :func:`tee`
call, eve... | the input peekable >>> next(iterator) # Move the iterator forward 'a' >>> lookahead(iterator) # Check next value 'b' >>> next(iterator) # Continue moving forward 'b'
``tee`` iterators are not threadsafe. A :exc:`RuntimeError` may be
raised when simultaneously using iterators returned by the same :func:`tee`
call, eve... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
43cd0293-c996-494e-ad34-09bb42e2cdef | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,254 | supabase-export-v2 | 06bc58e49f4bae8f | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) # takewhile() would lose the 'd' 'dEfGhI'
Note that the true iterator must be fully consumed
before the remainder iterator can generate valid results. """
it = iter(it)
transiti... | trusted_official_docs | CPython Docs | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) # takewhile() would lose the 'd' 'dEfGhI'
Note that the true iterator must be fully consumed
before the remainder iterator can generate valid results. """
it = iter(it)
transiti... | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) # takewhile() would lose the 'd' 'dEfGhI'
Note that the true iterator must be fully consumed
before the remainder iterator can generate valid results. """
it = iter(it)
transiti... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44e20c2b-6933-449a-bf18-4e2ae7b29b44 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,082 | supabase-export-v2 | babdd9bb8ba38ff9 | for prod in result: yield tuple(prod)
Before :func:`product` runs, it completely consumes the input iterables,
keeping pools of values in memory to generate the products. Accordingly,
it is only useful with finite inputs. | trusted_official_docs | CPython Docs | for prod in result: yield tuple(prod)
Before :func:`product` runs, it completely consumes the input iterables,
keeping pools of values in memory to generate the products. Accordingly,
it is only useful with finite inputs. | for prod in result: yield tuple(prod)
Before :func:`product` runs, it completely consumes the input iterables,
keeping pools of values in memory to generate the products. Accordingly,
it is only useful with finite inputs. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44f78c5a-f58a-43b9-9f7a-f237f0cb3942 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,093 | supabase-export-v2 | 3a2d20dd854c4317 | The difference between :func:`map` and :func:`starmap` parallels the distinction between ``function(a,b)`` and ``function(*c)``. Roughly equivalent to::
def starmap(function, iterable):
# starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000
for args in iterable:
yield function(*args) | trusted_official_docs | CPython Docs | The difference between :func:`map` and :func:`starmap` parallels the distinction between ``function(a,b)`` and ``function(*c)``. Roughly equivalent to::
def starmap(function, iterable):
# starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000
for args in iterable:
yield function(*args) | The difference between :func:`map` and :func:`starmap` parallels the distinction between ``function(a,b)`` and ``function(*c)``. Roughly equivalent to::
def starmap(function, iterable):
# starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000
for args in iterable:
yield function(*args) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
46e7dec4-ff48-4c59-96bf-284f0f2969f1 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,226 | supabase-export-v2 | 42b3c3fe5ad196b3 | >>> list(grouper('abcdefg', n=3, incomplete='ignore')) [('a', 'b', 'c'), ('d', 'e', 'f')]
>>> list(sliding_window('ABCDEFG', 1))
[('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)]
>>> list(sliding_window('ABCDEFG', 2))
[('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('F', 'G')]
>>> list(sliding_w... | trusted_official_docs | CPython Docs | >>> list(grouper('abcdefg', n=3, incomplete='ignore')) [('a', 'b', 'c'), ('d', 'e', 'f')]
>>> list(sliding_window('ABCDEFG', 1))
[('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)]
>>> list(sliding_window('ABCDEFG', 2))
[('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('F', 'G')]
>>> list(sliding_w... | >>> list(grouper('abcdefg', n=3, incomplete='ignore')) [('a', 'b', 'c'), ('d', 'e', 'f')]
>>> list(sliding_window('ABCDEFG', 1))
[('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)]
>>> list(sliding_window('ABCDEFG', 2))
[('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('F', 'G')]
>>> list(sliding_w... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
47b9a9b3-1d8a-4144-a38e-3233dee48d32 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,035 | supabase-export-v2 | 70db915681cb3ac4 | have sorted the data using the same key function). That behavior differs from SQL's GROUP BY which aggregates common elements regardless of their input order.
The returned group is itself an iterator that shares the underlying iterable
with :func:`groupby`. Because the source is shared, when the :func:`groupby`
objec... | trusted_official_docs | CPython Docs | have sorted the data using the same key function). That behavior differs from SQL's GROUP BY which aggregates common elements regardless of their input order.
The returned group is itself an iterator that shares the underlying iterable
with :func:`groupby`. Because the source is shared, when the :func:`groupby`
objec... | have sorted the data using the same key function). That behavior differs from SQL's GROUP BY which aggregates common elements regardless of their input order.
The returned group is itself an iterator that shares the underlying iterable
with :func:`groupby`. Because the source is shared, when the :func:`groupby`
objec... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
47fd509d-ba6e-4158-a0ae-ef2d7c2023d8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,215 | supabase-export-v2 | aeb60d4cc08e765a | input is consumed lazily >>> input_iterator = iter('AABCADEAF') >>> output_iterator = iter_index(input_iterator, 'A') >>> next(output_iterator) 0 >>> next(output_iterator) 1 >>> next(output_iterator) 4 >>> ''.join(input_iterator) 'DEAF'
>>> # Verify that the target value can be a sequence. >>> seq = [[10, 20], [30, 40]... | trusted_official_docs | CPython Docs | input is consumed lazily >>> input_iterator = iter('AABCADEAF') >>> output_iterator = iter_index(input_iterator, 'A') >>> next(output_iterator) 0 >>> next(output_iterator) 1 >>> next(output_iterator) 4 >>> ''.join(input_iterator) 'DEAF'
>>> # Verify that the target value can be a sequence. >>> seq = [[10, 20], [30, 40]... | input is consumed lazily >>> input_iterator = iter('AABCADEAF') >>> output_iterator = iter_index(input_iterator, 'A') >>> next(output_iterator) 0 >>> next(output_iterator) 1 >>> next(output_iterator) 4 >>> ''.join(input_iterator) 'DEAF'
>>> # Verify that the target value can be a sequence. >>> seq = [[10, 20], [30, 40]... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4861ae6a-60f8-48d8-b2cc-33a595349592 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,143 | supabase-export-v2 | b25ff375e47ed60e | def nth(iterable, n, default=None): "Returns the nth item or a default value." return next(islice(iterable, n, None), default)
def quantify(iterable, predicate=bool):
"Given a predicate that returns True or False, count the True results."
return sum(map(predicate, iterable)) | trusted_official_docs | CPython Docs | def nth(iterable, n, default=None): "Returns the nth item or a default value." return next(islice(iterable, n, None), default)
def quantify(iterable, predicate=bool):
"Given a predicate that returns True or False, count the True results."
return sum(map(predicate, iterable)) | def nth(iterable, n, default=None): "Returns the nth item or a default value." return next(islice(iterable, n, None), default)
def quantify(iterable, predicate=bool):
"Given a predicate that returns True or False, count the True results."
return sum(map(predicate, iterable)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4d982730-07de-4b37-9e5d-2a01e8d32e39 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,007 | supabase-export-v2 | 1885ba5638f9aa12 | .. function:: compress(data, selectors)
Make an iterator that returns elements from *data* where the
corresponding element in *selectors* is true. Stops when either the
*data* or *selectors* iterables have been exhausted. Roughly
equivalent to:: | trusted_official_docs | CPython Docs | .. function:: compress(data, selectors)
Make an iterator that returns elements from *data* where the
corresponding element in *selectors* is true. Stops when either the
*data* or *selectors* iterables have been exhausted. Roughly
equivalent to:: | .. function:: compress(data, selectors)
Make an iterator that returns elements from *data* where the
corresponding element in *selectors* is true. Stops when either the
*data* or *selectors* iterables have been exhausted. Roughly
equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5009d5d8-980b-4318-89e2-4229d3f88135 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,157 | supabase-export-v2 | 9df6ae9b9d6a91ab | interface to an iterator interface." # iter_except(d.popitem, KeyError) → non-blocking dictionary iterator with suppress(exception): if first is not None: yield first() while True: yield function()
# ==== Mathematical operations ==== | trusted_official_docs | CPython Docs | interface to an iterator interface." # iter_except(d.popitem, KeyError) → non-blocking dictionary iterator with suppress(exception): if first is not None: yield first() while True: yield function()
# ==== Mathematical operations ==== | interface to an iterator interface." # iter_except(d.popitem, KeyError) → non-blocking dictionary iterator with suppress(exception): if first is not None: yield first() while True: yield function()
# ==== Mathematical operations ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
50d5ea68-145b-4e7d-b42e-5a2f5c51c9d3 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,221 | supabase-export-v2 | 02837aa9f21bebfc | 999983) == 999952 * 999982 # large semiprime True >>> totient(6 ** 20) == 1 * 2**19 * 2 * 3**19 # repeated primes True
>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] | trusted_official_docs | CPython Docs | 999983) == 999952 * 999982 # large semiprime True >>> totient(6 ** 20) == 1 * 2**19 * 2 * 3**19 # repeated primes True
>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] | 999983) == 999952 * 999982 # large semiprime True >>> totient(6 ** 20) == 1 * 2**19 * 2 * 3**19 # repeated primes True
>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
519ca19e-c934-440e-8287-0575ff2493c7 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,074 | supabase-export-v2 | c0828ea5e7050a91 | `Cartesian product <https://en.wikipedia.org/wiki/Cartesian_product>`_ of the input iterables.
Roughly equivalent to nested for-loops in a generator expression. For example,
``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``. | trusted_official_docs | CPython Docs | `Cartesian product <https://en.wikipedia.org/wiki/Cartesian_product>`_ of the input iterables.
Roughly equivalent to nested for-loops in a generator expression. For example,
``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``. | `Cartesian product <https://en.wikipedia.org/wiki/Cartesian_product>`_ of the input iterables.
Roughly equivalent to nested for-loops in a generator expression. For example,
``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53647f72-b8d2-46cc-bee2-84d2b17f5686 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,201 | supabase-export-v2 | 2b72bff787f1ecb6 | 9) is None True >>> # Verify that the input is consumed lazily >>> it = iter('abcde') >>> nth(it, 2) 'c' >>> list(it) ['d', 'e']
>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
[True, True, True, False, False]
>>> [all_equal(s, key=str.casefold) for s in ('', 'A', 'AaAa', 'AAAB', 'AAABA')]
[True, True... | trusted_official_docs | CPython Docs | 9) is None True >>> # Verify that the input is consumed lazily >>> it = iter('abcde') >>> nth(it, 2) 'c' >>> list(it) ['d', 'e']
>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
[True, True, True, False, False]
>>> [all_equal(s, key=str.casefold) for s in ('', 'A', 'AaAa', 'AAAB', 'AAABA')]
[True, True... | 9) is None True >>> # Verify that the input is consumed lazily >>> it = iter('abcde') >>> nth(it, 2) 'c' >>> list(it) ['d', 'e']
>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
[True, True, True, False, False]
>>> [all_equal(s, key=str.casefold) for s in ('', 'A', 'AaAa', 'AAAB', 'AAABA')]
[True, True... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
545688ba-0c0b-4da0-8707-ccbedca1df80 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,041 | supabase-export-v2 | e1ea7f8442b249c8 | def _grouper(target_key): nonlocal curr_value, curr_key, exhausted yield curr_value for curr_value in iterator: curr_key = keyfunc(curr_value) if curr_key != target_key: return yield curr_value exhausted = True
try:
curr_value = next(iterator)
except StopIteration:
return
curr_key = keyfunc(curr_value) | trusted_official_docs | CPython Docs | def _grouper(target_key): nonlocal curr_value, curr_key, exhausted yield curr_value for curr_value in iterator: curr_key = keyfunc(curr_value) if curr_key != target_key: return yield curr_value exhausted = True
try:
curr_value = next(iterator)
except StopIteration:
return
curr_key = keyfunc(curr_value) | def _grouper(target_key): nonlocal curr_value, curr_key, exhausted yield curr_value for curr_value in iterator: curr_key = keyfunc(curr_value) if curr_key != target_key: return yield curr_value exhausted = True
try:
curr_value = next(iterator)
except StopIteration:
return
curr_key = keyfunc(curr_value) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
555e356d-186b-4f11-aa84-ea2fc03bcf73 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,137 | supabase-export-v2 | d2f9aa38cfacdfa7 | def repeatfunc(function, times=None, *args): "Repeat calls to a function with specified arguments." if times is None: return starmap(function, repeat(args)) return starmap(function, repeat(args, times))
def flatten(list_of_lists):
"Flatten one level of nesting."
return chain.from_iterable(list_of_lists) | trusted_official_docs | CPython Docs | def repeatfunc(function, times=None, *args): "Repeat calls to a function with specified arguments." if times is None: return starmap(function, repeat(args)) return starmap(function, repeat(args, times))
def flatten(list_of_lists):
"Flatten one level of nesting."
return chain.from_iterable(list_of_lists) | def repeatfunc(function, times=None, *args): "Repeat calls to a function with specified arguments." if times is None: return starmap(function, repeat(args)) return starmap(function, repeat(args, times))
def flatten(list_of_lists):
"Flatten one level of nesting."
return chain.from_iterable(list_of_lists) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
583353f7-7771-41a7-9c34-b199b9b18f76 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,128 | supabase-export-v2 | 3e0e468619f200b3 | ``compress()``, and ``pairwise()`` itertools started out as recipes. Currently, the ``sliding_window()``, ``derangements()``, and ``sieve()`` recipes are being tested to see whether they prove their worth.
Substantially all of these recipes and many, many others can be installed from
the :pypi:`more-itertools` project ... | trusted_official_docs | CPython Docs | ``compress()``, and ``pairwise()`` itertools started out as recipes. Currently, the ``sliding_window()``, ``derangements()``, and ``sieve()`` recipes are being tested to see whether they prove their worth.
Substantially all of these recipes and many, many others can be installed from
the :pypi:`more-itertools` project ... | ``compress()``, and ``pairwise()`` itertools started out as recipes. Currently, the ``sliding_window()``, ``derangements()``, and ``sieve()`` recipes are being tested to see whether they prove their worth.
Substantially all of these recipes and many, many others can be installed from
the :pypi:`more-itertools` project ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a0f8eb1-e222-4a5e-a775-059c4c44d780 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,158 | supabase-export-v2 | ee6d32f9c77fab4b | # ==== Mathematical operations ====
def multinomial(*counts):
"Number of distinct arrangements of a multiset."
# Counter('abracadabra').values() → 5 2 2 1 1
# multinomial(5, 2, 2, 1, 1) → 83160
return prod(map(comb, accumulate(counts), counts)) | trusted_official_docs | CPython Docs | # ==== Mathematical operations ====
def multinomial(*counts):
"Number of distinct arrangements of a multiset."
# Counter('abracadabra').values() → 5 2 2 1 1
# multinomial(5, 2, 2, 1, 1) → 83160
return prod(map(comb, accumulate(counts), counts)) | # ==== Mathematical operations ====
def multinomial(*counts):
"Number of distinct arrangements of a multiset."
# Counter('abracadabra').values() → 5 2 2 1 1
# multinomial(5, 2, 2, 1, 1) → 83160
return prod(map(comb, accumulate(counts), counts)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5b1a43bc-a1c7-4bd0-b9ef-b67117da9f93 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,180 | supabase-export-v2 | 4acfd8ea57f1c4e5 | n." # https://mathworld.wolfram.com/TotientFunction.html # totient(12) → 4 because len([1, 5, 7, 11]) == 4 for prime in set(factor(n)): n -= n // prime return n
# ==== Running statistics ==== | trusted_official_docs | CPython Docs | n." # https://mathworld.wolfram.com/TotientFunction.html # totient(12) → 4 because len([1, 5, 7, 11]) == 4 for prime in set(factor(n)): n -= n // prime return n
# ==== Running statistics ==== | n." # https://mathworld.wolfram.com/TotientFunction.html # totient(12) → 4 because len([1, 5, 7, 11]) == 4 for prime in set(factor(n)): n -= n // prime return n
# ==== Running statistics ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5d0c9d05-d299-47ef-8957-5f7fd64b35c9 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,207 | supabase-export-v2 | 23279ab8e49f8565 | 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)] >>> list(reshape(M, 12)) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]
>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
[(1, 11), (2, 22), (3, 33)]
>>> # Verify that the inputs are consumed lazily
>>> input1 = iter([1, 2, 3])
>>> input2 = iter([11, 22, 33])
>>> output_iterator = transpo... | trusted_official_docs | CPython Docs | 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)] >>> list(reshape(M, 12)) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]
>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
[(1, 11), (2, 22), (3, 33)]
>>> # Verify that the inputs are consumed lazily
>>> input1 = iter([1, 2, 3])
>>> input2 = iter([11, 22, 33])
>>> output_iterator = transpo... | 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)] >>> list(reshape(M, 12)) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]
>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
[(1, 11), (2, 22), (3, 33)]
>>> # Verify that the inputs are consumed lazily
>>> input1 = iter([1, 2, 3])
>>> input2 = iter([11, 22, 33])
>>> output_iterator = transpo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5f5a139f-06ce-4e64-ae30-eff61fce496c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,140 | supabase-export-v2 | f36b0dca52eadfc9 | def loops(n): "Loop n times. Like range(n) but without creating integers." # for _ in loops(100): ... return repeat(None, n)
def tail(n, iterable):
"Return an iterator over the last n items."
# tail(3, 'ABCDEFG') → E F G
return iter(deque(iterable, maxlen=n)) | trusted_official_docs | CPython Docs | def loops(n): "Loop n times. Like range(n) but without creating integers." # for _ in loops(100): ... return repeat(None, n)
def tail(n, iterable):
"Return an iterator over the last n items."
# tail(3, 'ABCDEFG') → E F G
return iter(deque(iterable, maxlen=n)) | def loops(n): "Loop n times. Like range(n) but without creating integers." # for _ in loops(100): ... return repeat(None, n)
def tail(n, iterable):
"Return an iterator over the last n items."
# tail(3, 'ABCDEFG') → E F G
return iter(deque(iterable, maxlen=n)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
60f873e6-2731-4db2-abab-78788581b438 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,235 | supabase-export-v2 | 7856839d536c1435 | list(unique([[1, 2], [3, 4], [1, 2]])) [[1, 2], [3, 4]] >>> list(unique('ABBcCAD', str.casefold)) ['A', 'B', 'c', 'D'] >>> list(unique('ABBcCAD', str.casefold, reverse=True)) ['D', 'c', 'B', 'A']
>>> d = dict(a=1, b=2, c=3)
>>> it = iter_except(d.popitem, KeyError)
>>> d['d'] = 4
>>> next(it)
('d', 4)
>>> next(it)... | trusted_official_docs | CPython Docs | list(unique([[1, 2], [3, 4], [1, 2]])) [[1, 2], [3, 4]] >>> list(unique('ABBcCAD', str.casefold)) ['A', 'B', 'c', 'D'] >>> list(unique('ABBcCAD', str.casefold, reverse=True)) ['D', 'c', 'B', 'A']
>>> d = dict(a=1, b=2, c=3)
>>> it = iter_except(d.popitem, KeyError)
>>> d['d'] = 4
>>> next(it)
('d', 4)
>>> next(it)... | list(unique([[1, 2], [3, 4], [1, 2]])) [[1, 2], [3, 4]] >>> list(unique('ABBcCAD', str.casefold)) ['A', 'B', 'c', 'D'] >>> list(unique('ABBcCAD', str.casefold, reverse=True)) ['D', 'c', 'B', 'A']
>>> d = dict(a=1, b=2, c=3)
>>> it = iter_except(d.popitem, KeyError)
>>> d['d'] = 4
>>> next(it)
('d', 4)
>>> next(it)... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
65d82398-f158-4826-b98a-47b4d8e0b2af | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,193 | supabase-export-v2 | 7e0edfcab738854c | for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]): ... print(list(map(operator.itemgetter(1), g))) ... [1] [4, 5, 6] [10] [15, 16, 17, 18] [22] [25, 26, 27, 28]
Now, we test all of the itertool recipes | trusted_official_docs | CPython Docs | for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]): ... print(list(map(operator.itemgetter(1), g))) ... [1] [4, 5, 6] [10] [15, 16, 17, 18] [22] [25, 26, 27, 28]
Now, we test all of the itertool recipes | for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]): ... print(list(map(operator.itemgetter(1), g))) ... [1] [4, 5, 6] [10] [15, 16, 17, 18] [22] [25, 26, 27, 28]
Now, we test all of the itertool recipes | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
68c05480-8b25-4639-a1fc-c23d60411cc7 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,978 | supabase-export-v2 | b0c6930b70c9621f | Roughly equivalent to::
def batched(iterable, n, *, strict=False):
# batched('ABCDEFG', 3) → ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
iterator = iter(iterable)
while batch := tuple(islice(iterator, n)):
if strict and len(batch) != n:
raise ValueError('batched(): incomplete batch')
yield ba... | trusted_official_docs | CPython Docs | Roughly equivalent to::
def batched(iterable, n, *, strict=False):
# batched('ABCDEFG', 3) → ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
iterator = iter(iterable)
while batch := tuple(islice(iterator, n)):
if strict and len(batch) != n:
raise ValueError('batched(): incomplete batch')
yield ba... | Roughly equivalent to::
def batched(iterable, n, *, strict=False):
# batched('ABCDEFG', 3) → ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
iterator = iter(iterable)
while batch := tuple(islice(iterator, n)):
if strict and len(batch) != n:
raise ValueError('batched(): incomplete batch')
yield ba... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
68e82d47-4c4e-4754-9c0f-b11122fa3c18 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,132 | supabase-export-v2 | 63fd78f5ded1fa24 | .. testcode::
from itertools import (accumulate, batched, chain, combinations, compress,
count, cycle, filterfalse, groupby, islice, permutations, product,
repeat, starmap, tee, zip_longest)
from collections import Counter, deque
from contextlib import suppress
from functools import reduce
from heapq import heapp... | trusted_official_docs | CPython Docs | .. testcode::
from itertools import (accumulate, batched, chain, combinations, compress,
count, cycle, filterfalse, groupby, islice, permutations, product,
repeat, starmap, tee, zip_longest)
from collections import Counter, deque
from contextlib import suppress
from functools import reduce
from heapq import heapp... | .. testcode::
from itertools import (accumulate, batched, chain, combinations, compress,
count, cycle, filterfalse, groupby, islice, permutations, product,
repeat, starmap, tee, zip_longest)
from collections import Counter, deque
from contextlib import suppress
from functools import reduce
from heapq import heapp... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6cb0af11-c126-4c24-95f2-3609a15a6b6c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,233 | supabase-export-v2 | 1a247a5fa75d82d8 | 'c', 'D'] >>> # Verify that the input is consumed lazily >>> input_iterator = iter('AAAABBBCCDAABBB') >>> output_iterator = unique_everseen(input_iterator) >>> next(output_iterator) 'A' >>> ''.join(input_iterator) 'AAABBBCCDAABBB'
>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']
>>> list(un... | trusted_official_docs | CPython Docs | 'c', 'D'] >>> # Verify that the input is consumed lazily >>> input_iterator = iter('AAAABBBCCDAABBB') >>> output_iterator = unique_everseen(input_iterator) >>> next(output_iterator) 'A' >>> ''.join(input_iterator) 'AAABBBCCDAABBB'
>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']
>>> list(un... | 'c', 'D'] >>> # Verify that the input is consumed lazily >>> input_iterator = iter('AAAABBBCCDAABBB') >>> output_iterator = unique_everseen(input_iterator) >>> next(output_iterator) 'A' >>> ''.join(input_iterator) 'AAABBBCCDAABBB'
>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']
>>> list(un... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6cdf0f29-0e0e-4f3b-933e-cfe4e524d31b | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,189 | supabase-export-v2 | ea335b842e1b20e6 | ... print('Check %d is for $%.2f' % (checknum, amount)) ... Check 1200 is for $120.15 Check 1201 is for $764.05 Check 1202 is for $823.14
>>> import operator
>>> for cube in map(operator.pow, range(1,4), repeat(3)):
... print(cube)
... 1
8
27 | trusted_official_docs | CPython Docs | ... print('Check %d is for $%.2f' % (checknum, amount)) ... Check 1200 is for $120.15 Check 1201 is for $764.05 Check 1202 is for $823.14
>>> import operator
>>> for cube in map(operator.pow, range(1,4), repeat(3)):
... print(cube)
... 1
8
27 | ... print('Check %d is for $%.2f' % (checknum, amount)) ... Check 1200 is for $120.15 Check 1201 is for $764.05 Check 1202 is for $823.14
>>> import operator
>>> for cube in map(operator.pow, range(1,4), repeat(3)):
... print(cube)
... 1
8
27 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6d8fe442-50f7-4c87-9251-6c283d3f0ccf | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,944 | supabase-export-v2 | 148f0f7726425d99 | **General iterators:**
============================ ============================ ================================================= =============================================================
Iterator Arguments Results Example
============================ ============================ ==================================... | trusted_official_docs | CPython Docs | **General iterators:**
============================ ============================ ================================================= =============================================================
Iterator Arguments Results Example
============================ ============================ ==================================... | **General iterators:**
============================ ============================ ================================================= =============================================================
Iterator Arguments Results Example
============================ ============================ ==================================... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e9cc424-68a1-4e6e-9046-67a150a5f2eb | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,000 | supabase-export-v2 | 25de544b8376f3fa | lexicographic order according to the order of the input *iterable*. if the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, the generated combinations
will also be unique. | trusted_official_docs | CPython Docs | lexicographic order according to the order of the input *iterable*. if the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, the generated combinations
will also be unique. | lexicographic order according to the order of the input *iterable*. if the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, the generated combinations
will also be unique. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7111720d-cf33-41cf-9b81-b5a6e14e3c15 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,252 | supabase-export-v2 | d37444c43dc72991 | [] while r: c, n, r = c*r//n, n-1, r-1 while index >= c: index -= c c, n = c*(n-r)//n, n-1 result.append(pool[-1-n]) return tuple(result)
def before_and_after(predicate, it):
""" Variant of takewhile() that allows complete
access to the remainder of the iterator. | trusted_official_docs | CPython Docs | [] while r: c, n, r = c*r//n, n-1, r-1 while index >= c: index -= c c, n = c*(n-r)//n, n-1 result.append(pool[-1-n]) return tuple(result)
def before_and_after(predicate, it):
""" Variant of takewhile() that allows complete
access to the remainder of the iterator. | [] while r: c, n, r = c*r//n, n-1, r-1 while index >= c: index -= c c, n = c*(n-r)//n, n-1 result.append(pool[-1-n]) return tuple(result)
def before_and_after(predicate, it):
""" Variant of takewhile() that allows complete
access to the remainder of the iterator. | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.