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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
07378ac1-f5f6-4ec2-8e5d-cdb3cac2801f | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,001 | supabase-export-v2 | a8858bc812d8efdb | A theoretical benefit is that it's easier to construct a mathematical proof that a functional program is correct.
For a long time researchers have been interested in finding ways to
mathematically prove programs correct. This is different from testing a program
on numerous inputs and concluding that its output is usual... | trusted_official_docs | CPython Docs | A theoretical benefit is that it's easier to construct a mathematical proof that a functional program is correct.
For a long time researchers have been interested in finding ways to
mathematically prove programs correct. This is different from testing a program
on numerous inputs and concluding that its output is usual... | A theoretical benefit is that it's easier to construct a mathematical proof that a functional program is correct.
For a long time researchers have been interested in finding ways to
mathematically prove programs correct. This is different from testing a program
on numerous inputs and concluding that its output is usual... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0acb5e54-938c-4932-a897-0cc1cce01aad | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,121 | supabase-export-v2 | e0e1415b9eeb35f0 | :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elements are true values:
>>> any([0, 1, 0])
True
>>> any([0, 0, 0])
False
>>> any([1, 1, 1])
True
>>> all([0, 1, 0])
False
>>> all([0, 0, 0])
False
>>> all([1, 1, 1])
True | trusted_official_docs | CPython Docs | :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elements are true values:
>>> any([0, 1, 0])
True
>>> any([0, 0, 0])
False
>>> any([1, 1, 1])
True
>>> all([0, 1, 0])
False
>>> all([0, 0, 0])
False
>>> all([1, 1, 1])
True | :func:`any` returns ``True`` if any element in the iterable is a true value, and :func:`all` returns ``True`` if all of the elements are true values:
>>> any([0, 1, 0])
True
>>> any([0, 0, 0])
False
>>> any([1, 1, 1])
True
>>> all([0, 1, 0])
False
>>> all([0, 0, 0])
False
>>> all([1, 1, 1])
True | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0dc2ba57-fab7-45f8-b9e3-83731ce07bab | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,098 | supabase-export-v2 | 8b0a25c428dcca93 | and doing anything else is illegal and will trigger a :exc:`RuntimeError`. :meth:`~generator.close` will also be called by Python's garbage collector when the generator is garbage-collected.
If you need to run cleanup code when a :exc:`GeneratorExit` occurs, I suggest
using a ``try: ... finally:`` suite instead of cat... | trusted_official_docs | CPython Docs | and doing anything else is illegal and will trigger a :exc:`RuntimeError`. :meth:`~generator.close` will also be called by Python's garbage collector when the generator is garbage-collected.
If you need to run cleanup code when a :exc:`GeneratorExit` occurs, I suggest
using a ``try: ... finally:`` suite instead of cat... | and doing anything else is illegal and will trigger a :exc:`RuntimeError`. :meth:`~generator.close` will also be called by Python's garbage collector when the generator is garbage-collected.
If you need to run cleanup code when a :exc:`GeneratorExit` occurs, I suggest
using a ``try: ... finally:`` suite instead of cat... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e9e537b-c295-44fc-a1c4-da6ec05bcc07 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,197 | supabase-export-v2 | efba9d9b4d9a6bf8 | :func:`functools.reduce`, you'll add up all the elements of the iterable. This case is so common that there's a special built-in called :func:`sum` to compute it:
>>> import functools, operator
>>> functools.reduce(operator.add, [1, 2, 3, 4], 0)
10
>>> sum([1, 2, 3, 4])
10
>>> sum([])
0 | trusted_official_docs | CPython Docs | :func:`functools.reduce`, you'll add up all the elements of the iterable. This case is so common that there's a special built-in called :func:`sum` to compute it:
>>> import functools, operator
>>> functools.reduce(operator.add, [1, 2, 3, 4], 0)
10
>>> sum([1, 2, 3, 4])
10
>>> sum([])
0 | :func:`functools.reduce`, you'll add up all the elements of the iterable. This case is so common that there's a special built-in called :func:`sum` to compute it:
>>> import functools, operator
>>> functools.reduce(operator.add, [1, 2, 3, 4], 0)
10
>>> sum([1, 2, 3, 4])
10
>>> sum([])
0 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
11ce42cc-e415-472b-bace-883b690b20f1 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,075 | supabase-export-v2 | e7a6198c769d10a4 | You could equally write ``for i in generate_ints(5)``, or ``a, b, c = generate_ints(3)``.
Inside a generator function, ``return value`` causes ``StopIteration(value)``
to be raised from the :meth:`~generator.__next__` method. Once this happens, or
the bottom of the function is reached, the procession of values ends and... | trusted_official_docs | CPython Docs | You could equally write ``for i in generate_ints(5)``, or ``a, b, c = generate_ints(3)``.
Inside a generator function, ``return value`` causes ``StopIteration(value)``
to be raised from the :meth:`~generator.__next__` method. Once this happens, or
the bottom of the function is reached, the procession of values ends and... | You could equally write ``for i in generate_ints(5)``, or ``a, b, c = generate_ints(3)``.
Inside a generator function, ``return value`` causes ``StopIteration(value)``
to be raised from the :meth:`~generator.__next__` method. Once this happens, or
the bottom of the function is reached, the procession of values ends and... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
13608567-08ad-4d20-8c7e-8263ebb86cb4 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,055 | supabase-export-v2 | 0d23f37a7dc12c0c | successive values of ``expression``. The ``if`` clauses are all optional; if present, ``expression`` is only evaluated and added to the result when ``condition`` is true.
Generator expressions always have to be written inside parentheses, but the
parentheses signalling a function call also count. If you want to create ... | trusted_official_docs | CPython Docs | successive values of ``expression``. The ``if`` clauses are all optional; if present, ``expression`` is only evaluated and added to the result when ``condition`` is true.
Generator expressions always have to be written inside parentheses, but the
parentheses signalling a function call also count. If you want to create ... | successive values of ``expression``. The ``if`` clauses are all optional; if present, ``expression`` is only evaluated and added to the result when ``condition`` is true.
Generator expressions always have to be written inside parentheses, but the
parentheses signalling a function call also count. If you want to create ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
15056df6-b453-4abf-a1c0-e2501108cfd6 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,126 | supabase-export-v2 | 54d9a14fe4fe3a70 | all of the same length. If the iterables are of different lengths, the resulting stream will be the same length as the shortest iterable. ::
zip(['a', 'b'], (1, 2, 3)) =>
('a', 1), ('b', 2) | trusted_official_docs | CPython Docs | all of the same length. If the iterables are of different lengths, the resulting stream will be the same length as the shortest iterable. ::
zip(['a', 'b'], (1, 2, 3)) =>
('a', 1), ('b', 2) | all of the same length. If the iterables are of different lengths, the resulting stream will be the same length as the shortest iterable. ::
zip(['a', 'b'], (1, 2, 3)) =>
('a', 1), ('b', 2) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
18498477-2729-458c-bf97-4ddd3b186e99 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,064 | supabase-export-v2 | 67ffb83f93a24997 | is creating a tuple, it must be surrounded with parentheses. The first list comprehension below is a syntax error, while the second one is correct::
# Syntax error
[x, y for x in seq1 for y in seq2]
# Correct
[(x, y) for x in seq1 for y in seq2] | trusted_official_docs | CPython Docs | is creating a tuple, it must be surrounded with parentheses. The first list comprehension below is a syntax error, while the second one is correct::
# Syntax error
[x, y for x in seq1 for y in seq2]
# Correct
[(x, y) for x in seq1 for y in seq2] | is creating a tuple, it must be surrounded with parentheses. The first list comprehension below is a syntax error, while the second one is correct::
# Syntax error
[x, y for x in seq1 for y in seq2]
# Correct
[(x, y) for x in seq1 for y in seq2] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
18e52ed3-93f4-4138-b8b2-3e8ce9b59d22 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,142 | supabase-export-v2 | 15ffd150e3fcbeb8 | value for *step*, elements will be skipped accordingly. Unlike Python's string and list slicing, you can't use negative values for *start*, *stop*, or *step*. ::
itertools.islice(range(10), 8) =>
0, 1, 2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8) =>
2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8, 2) =>
2,... | trusted_official_docs | CPython Docs | value for *step*, elements will be skipped accordingly. Unlike Python's string and list slicing, you can't use negative values for *start*, *stop*, or *step*. ::
itertools.islice(range(10), 8) =>
0, 1, 2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8) =>
2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8, 2) =>
2,... | value for *step*, elements will be skipped accordingly. Unlike Python's string and list slicing, you can't use negative values for *start*, *stop*, or *step*. ::
itertools.islice(range(10), 8) =>
0, 1, 2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8) =>
2, 3, 4, 5, 6, 7
itertools.islice(range(10), 2, 8, 2) =>
2,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d50ab82-fd5b-4b4a-9c61-f047276230cc | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,214 | supabase-export-v2 | 1448264af015309d | expression. ``lambda`` takes a number of parameters and an expression combining these parameters, and creates an anonymous function that returns the value of the expression::
adder = lambda x, y: x+y | trusted_official_docs | CPython Docs | expression. ``lambda`` takes a number of parameters and an expression combining these parameters, and creates an anonymous function that returns the value of the expression::
adder = lambda x, y: x+y | expression. ``lambda`` takes a number of parameters and an expression combining these parameters, and creates an anonymous function that returns the value of the expression::
adder = lambda x, y: x+y | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1e092ec6-03f1-496e-8613-7181f9cb3cb6 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,117 | supabase-export-v2 | 163a306b02cdc0a3 | f = open('data.txt', 'r') for i, line in enumerate(f): if line.strip() == '': print('Blank line at line #%i' % i)
:func:`sorted(iterable, key=None, reverse=False) <sorted>` collects all the
elements of the iterable into a list, sorts the list, and returns the sorted
result. The *key* and *reverse* arguments are passed ... | trusted_official_docs | CPython Docs | f = open('data.txt', 'r') for i, line in enumerate(f): if line.strip() == '': print('Blank line at line #%i' % i)
:func:`sorted(iterable, key=None, reverse=False) <sorted>` collects all the
elements of the iterable into a list, sorts the list, and returns the sorted
result. The *key* and *reverse* arguments are passed ... | f = open('data.txt', 'r') for i, line in enumerate(f): if line.strip() == '': print('Blank line at line #%i' % i)
:func:`sorted(iterable, key=None, reverse=False) <sorted>` collects all the
elements of the iterable into a list, sorts the list, and returns the sorted
result. The *key* and *reverse* arguments are passed ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1ecffc4b-2153-4753-8741-54371b7071b2 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,160 | supabase-export-v2 | 1d74dc44c50665e8 | :func:`itertools.dropwhile(predicate, iter) <itertools.dropwhile>` discards elements while the predicate returns true, and then returns the rest of the iterable's results. ::
itertools.dropwhile(less_than_10, itertools.count()) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... | trusted_official_docs | CPython Docs | :func:`itertools.dropwhile(predicate, iter) <itertools.dropwhile>` discards elements while the predicate returns true, and then returns the rest of the iterable's results. ::
itertools.dropwhile(less_than_10, itertools.count()) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... | :func:`itertools.dropwhile(predicate, iter) <itertools.dropwhile>` discards elements while the predicate returns true, and then returns the rest of the iterable's results. ::
itertools.dropwhile(less_than_10, itertools.count()) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
20198810-7fcf-442f-a39a-ec748dc9b892 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,013 | supabase-export-v2 | 19a7caf3e55364ca | all the XML files in the directory, or a function that takes a filename and returns its contents, can be applied to many different situations.
Over time you'll form a personal library of utilities. Often you'll assemble
new programs by arranging existing functions in a new configuration and writing
a few functions spec... | trusted_official_docs | CPython Docs | all the XML files in the directory, or a function that takes a filename and returns its contents, can be applied to many different situations.
Over time you'll form a personal library of utilities. Often you'll assemble
new programs by arranging existing functions in a new configuration and writing
a few functions spec... | all the XML files in the directory, or a function that takes a filename and returns its contents, can be applied to many different situations.
Over time you'll form a personal library of utilities. Often you'll assemble
new programs by arranging existing functions in a new configuration and writing
a few functions spec... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
20d5328f-4cb4-48b4-a016-b9ae43755716 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,996 | supabase-export-v2 | 8bf950b15debb220 | internally. For example, the implementation of a function will still use assignments to local variables, but won't modify global variables or have other side effects.
Functional programming can be considered the opposite of object-oriented
programming. Objects are little capsules containing some internal state along
wi... | trusted_official_docs | CPython Docs | internally. For example, the implementation of a function will still use assignments to local variables, but won't modify global variables or have other side effects.
Functional programming can be considered the opposite of object-oriented
programming. Objects are little capsules containing some internal state along
wi... | internally. For example, the implementation of a function will still use assignments to local variables, but won't modify global variables or have other side effects.
Functional programming can be considered the opposite of object-oriented
programming. Objects are little capsules containing some internal state along
wi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
23eeb0af-1854-4c21-ab5d-6de3545542fd | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,022 | supabase-export-v2 | 3a5a3d5c0f673962 | statement ``for X in Y``, Y must be an iterator or some object for which :func:`iter` can create an iterator. These two statements are equivalent::
for i in iter(obj):
print(i) | trusted_official_docs | CPython Docs | statement ``for X in Y``, Y must be an iterator or some object for which :func:`iter` can create an iterator. These two statements are equivalent::
for i in iter(obj):
print(i) | statement ``for X in Y``, Y must be an iterator or some object for which :func:`iter` can create an iterator. These two statements are equivalent::
for i in iter(obj):
print(i) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
258d6a19-113c-4171-974f-d229edda1af7 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,047 | supabase-export-v2 | bbac5a337dfb8e2d | >>> # Generator expression -- returns iterator >>> stripped_iter = (line.strip() for line in line_list)
>>> # List comprehension -- returns list
>>> stripped_list = [line.strip() for line in line_list] | trusted_official_docs | CPython Docs | >>> # Generator expression -- returns iterator >>> stripped_iter = (line.strip() for line in line_list)
>>> # List comprehension -- returns list
>>> stripped_list = [line.strip() for line in line_list] | >>> # Generator expression -- returns iterator >>> stripped_iter = (line.strip() for line in line_list)
>>> # List comprehension -- returns list
>>> stripped_list = [line.strip() for line in line_list] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
25b79a8d-9f5d-466a-846b-e6c078871aea | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,138 | supabase-export-v2 | c05b05d4643d6e9f | :func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided element *n* times, or returns the element endlessly if *n* is not provided. ::
itertools.repeat('abc') =>
abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) =>
abc, abc, abc, abc, abc | trusted_official_docs | CPython Docs | :func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided element *n* times, or returns the element endlessly if *n* is not provided. ::
itertools.repeat('abc') =>
abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) =>
abc, abc, abc, abc, abc | :func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided element *n* times, or returns the element endlessly if *n* is not provided. ::
itertools.repeat('abc') =>
abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) =>
abc, abc, abc, abc, abc | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
26abb91a-7a66-4a4e-96e3-5851026b3f11 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,143 | supabase-export-v2 | 7876656a0e79bf49 | 1, 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8) => 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8, 2) => 2, 4, 6
:func:`itertools.tee(iter, [n]) <itertools.tee>` replicates an iterator; it
returns *n* independent iterators that will all return the contents of the
source iterator. If you don't supply a value fo... | trusted_official_docs | CPython Docs | 1, 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8) => 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8, 2) => 2, 4, 6
:func:`itertools.tee(iter, [n]) <itertools.tee>` replicates an iterator; it
returns *n* independent iterators that will all return the contents of the
source iterator. If you don't supply a value fo... | 1, 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8) => 2, 3, 4, 5, 6, 7 itertools.islice(range(10), 2, 8, 2) => 2, 4, 6
:func:`itertools.tee(iter, [n]) <itertools.tee>` replicates an iterator; it
returns *n* independent iterators that will all return the contents of the
source iterator. If you don't supply a value fo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
288370dc-2a89-4ff5-a1fc-4b5e2d9fa3b9 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,131 | supabase-export-v2 | 1961b5712b6d52ba | The module's functions fall into a few broad classes:
* Functions that create a new iterator based on an existing iterator. * Functions for treating an iterator's elements as function arguments. * Functions for selecting portions of an iterator's output. * A function for grouping an iterator's output. | trusted_official_docs | CPython Docs | The module's functions fall into a few broad classes:
* Functions that create a new iterator based on an existing iterator. * Functions for treating an iterator's elements as function arguments. * Functions for selecting portions of an iterator's output. * A function for grouping an iterator's output. | The module's functions fall into a few broad classes:
* Functions that create a new iterator based on an existing iterator. * Functions for treating an iterator's elements as function arguments. * Functions for selecting portions of an iterator's output. * A function for grouping an iterator's output. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
31e696af-80e0-49f7-b63a-8c7ba3f3a1c4 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,108 | supabase-export-v2 | 72ebc12f0731332b | You can of course achieve the same effect with a list comprehension.
:func:`filter(predicate, iter) <filter>` returns an iterator over all the
sequence elements that meet a certain condition, and is similarly duplicated by
list comprehensions. A **predicate** is a function that returns the truth
value of some condition... | trusted_official_docs | CPython Docs | You can of course achieve the same effect with a list comprehension.
:func:`filter(predicate, iter) <filter>` returns an iterator over all the
sequence elements that meet a certain condition, and is similarly duplicated by
list comprehensions. A **predicate** is a function that returns the truth
value of some condition... | You can of course achieve the same effect with a list comprehension.
:func:`filter(predicate, iter) <filter>` returns an iterator over all the
sequence elements that meet a certain condition, and is similarly duplicated by
list comprehensions. A **predicate** is a function that returns the truth
value of some condition... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
349b9610-c244-4524-bcef-b4609d29bd56 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,031 | supabase-export-v2 | 534c0df887885e16 | Data Types That Support Iterators ---------------------------------
We've already seen how lists and tuples support iterators. In fact, any Python
sequence type, such as strings, will automatically support creation of an
iterator. | trusted_official_docs | CPython Docs | Data Types That Support Iterators ---------------------------------
We've already seen how lists and tuples support iterators. In fact, any Python
sequence type, such as strings, will automatically support creation of an
iterator. | Data Types That Support Iterators ---------------------------------
We've already seen how lists and tuples support iterators. In fact, any Python
sequence type, such as strings, will automatically support creation of an
iterator. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3528c04a-76c8-49ed-8ea3-50e8d7f798fa | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,118 | supabase-export-v2 | dfd2b0e60f329550 | a list, sorts the list, and returns the sorted result. The *key* and *reverse* arguments are passed through to the constructed list's :meth:`~list.sort` method. ::
>>> import random
>>> # Generate 8 random numbers between [0, 10000)
>>> rand_list = random.sample(range(10000), 8)
>>> rand_list #doctest: +SKIP
[769, ... | trusted_official_docs | CPython Docs | a list, sorts the list, and returns the sorted result. The *key* and *reverse* arguments are passed through to the constructed list's :meth:`~list.sort` method. ::
>>> import random
>>> # Generate 8 random numbers between [0, 10000)
>>> rand_list = random.sample(range(10000), 8)
>>> rand_list #doctest: +SKIP
[769, ... | a list, sorts the list, and returns the sorted result. The *key* and *reverse* arguments are passed through to the constructed list's :meth:`~list.sort` method. ::
>>> import random
>>> # Generate 8 random numbers between [0, 10000)
>>> rand_list = random.sample(range(10000), 8)
>>> rand_list #doctest: +SKIP
[769, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
36496e26-e077-4d86-93f4-1b5c6d72b829 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,068 | supabase-export-v2 | 4a91d6b8d4433b7e | What if you could later resume the function where it left off? This is what generators provide; they can be thought of as resumable functions.
Here's the simplest example of a generator function: | trusted_official_docs | CPython Docs | What if you could later resume the function where it left off? This is what generators provide; they can be thought of as resumable functions.
Here's the simplest example of a generator function: | What if you could later resume the function where it left off? This is what generators provide; they can be thought of as resumable functions.
Here's the simplest example of a generator function: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
373ca34b-8db8-486b-a47b-3e3635826607 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,030 | supabase-export-v2 | 5251ef4a4dd1dba3 | consume all of the iterator's output, and if you need to do something different with the same stream, you'll have to create a new iterator.
Data Types That Support Iterators
--------------------------------- | trusted_official_docs | CPython Docs | consume all of the iterator's output, and if you need to do something different with the same stream, you'll have to create a new iterator.
Data Types That Support Iterators
--------------------------------- | consume all of the iterator's output, and if you need to do something different with the same stream, you'll have to create a new iterator.
Data Types That Support Iterators
--------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3affe025-f647-4890-ba7c-fcdee1f6ede0 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,175 | supabase-export-v2 | f0ea74e047cab659 | The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a' strings came from different positions.
The :func:`itertools.combinations_with_replacement(iterable, r) <itertools.combinations_with_replacement>`
function relaxes a different constraint: elements can be repeated
within a single tuple. Conceptually an... | trusted_official_docs | CPython Docs | The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a' strings came from different positions.
The :func:`itertools.combinations_with_replacement(iterable, r) <itertools.combinations_with_replacement>`
function relaxes a different constraint: elements can be repeated
within a single tuple. Conceptually an... | The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a' strings came from different positions.
The :func:`itertools.combinations_with_replacement(iterable, r) <itertools.combinations_with_replacement>`
function relaxes a different constraint: elements can be repeated
within a single tuple. Conceptually an... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3c20abec-36df-4184-b9c3-0e14bb7bc795 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,249 | supabase-export-v2 | 3da80d187f76173b | chapter of David Mertz's book :title-reference:`Text Processing in Python` discusses functional programming for text processing, in the section titled "Utilizing Higher-Order Functions in Text Processing".
Mertz also wrote a 3-part series of articles on functional programming
for IBM's DeveloperWorks site; see
`part 1 ... | trusted_official_docs | CPython Docs | chapter of David Mertz's book :title-reference:`Text Processing in Python` discusses functional programming for text processing, in the section titled "Utilizing Higher-Order Functions in Text Processing".
Mertz also wrote a 3-part series of articles on functional programming
for IBM's DeveloperWorks site; see
`part 1 ... | chapter of David Mertz's book :title-reference:`Text Processing in Python` discusses functional programming for text processing, in the section titled "Utilizing Higher-Order Functions in Text Processing".
Mertz also wrote a 3-part series of articles on functional programming
for IBM's DeveloperWorks site; see
`part 1 ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3d6033a7-bbef-4b1f-9ffb-4ef8abef5974 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,041 | supabase-export-v2 | ac7368a9fab86e61 | Sets can take their contents from an iterable and let you iterate over the set's elements::
>>> S = {2, 3, 5, 7, 11, 13}
>>> for i in S:
... print(i)
2
3
5
7
11
13 | trusted_official_docs | CPython Docs | Sets can take their contents from an iterable and let you iterate over the set's elements::
>>> S = {2, 3, 5, 7, 11, 13}
>>> for i in S:
... print(i)
2
3
5
7
11
13 | Sets can take their contents from an iterable and let you iterate over the set's elements::
>>> S = {2, 3, 5, 7, 11, 13}
>>> for i in S:
... print(i)
2
3
5
7
11
13 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
40034724-ad11-4a94-bd89-e193edc7468a | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,995 | supabase-export-v2 | 7245a684b1749118 | returns a useful value. Both are called only for their side effects of sending some text to the screen or pausing execution for a second.
Python programs written in functional style usually won't go to the extreme of
avoiding all I/O or all assignments; instead, they'll provide a
functional-appearing interface but will... | trusted_official_docs | CPython Docs | returns a useful value. Both are called only for their side effects of sending some text to the screen or pausing execution for a second.
Python programs written in functional style usually won't go to the extreme of
avoiding all I/O or all assignments; instead, they'll provide a
functional-appearing interface but will... | returns a useful value. Both are called only for their side effects of sending some text to the screen or pausing execution for a second.
Python programs written in functional style usually won't go to the extreme of
avoiding all I/O or all assignments; instead, they'll provide a
functional-appearing interface but will... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4049b969-78e6-4ebd-a854-da8cea59c868 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,162 | supabase-export-v2 | dd7d3862bc91d2da | itertools.dropwhile(is_even, itertools.count()) => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
:func:`itertools.compress(data, selectors) <itertools.compress>` takes two
iterators and returns only those elements of *data* for which the corresponding
element of *selectors* is true, stopping whenever either one is exhausted:: | trusted_official_docs | CPython Docs | itertools.dropwhile(is_even, itertools.count()) => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
:func:`itertools.compress(data, selectors) <itertools.compress>` takes two
iterators and returns only those elements of *data* for which the corresponding
element of *selectors* is true, stopping whenever either one is exhausted:: | itertools.dropwhile(is_even, itertools.count()) => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
:func:`itertools.compress(data, selectors) <itertools.compress>` takes two
iterators and returns only those elements of *data* for which the corresponding
element of *selectors* is true, stopping whenever either one is exhausted:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4079faf5-8006-474f-ae8e-faa2f5050323 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,025 | supabase-export-v2 | 509b768e5556f8d5 | Iterators can be materialized as lists or tuples by using the :func:`list` or :func:`tuple` constructor functions:
>>> L = [1, 2, 3]
>>> iterator = iter(L)
>>> t = tuple(iterator)
>>> t
(1, 2, 3) | trusted_official_docs | CPython Docs | Iterators can be materialized as lists or tuples by using the :func:`list` or :func:`tuple` constructor functions:
>>> L = [1, 2, 3]
>>> iterator = iter(L)
>>> t = tuple(iterator)
>>> t
(1, 2, 3) | Iterators can be materialized as lists or tuples by using the :func:`list` or :func:`tuple` constructor functions:
>>> L = [1, 2, 3]
>>> iterator = iter(L)
>>> t = tuple(iterator)
>>> t
(1, 2, 3) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
41216d78-070b-4b55-9a49-1bdbd424d89c | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,991 | supabase-export-v2 | c76efab06b0f300f | some way. Smalltalk and Java are object-oriented languages. C++ and Python are languages that support object-oriented programming, but don't force the use of object-oriented features.
* **Functional** programming decomposes a problem into a set of functions. Ideally, functions only take inputs and produce outputs, and ... | trusted_official_docs | CPython Docs | some way. Smalltalk and Java are object-oriented languages. C++ and Python are languages that support object-oriented programming, but don't force the use of object-oriented features.
* **Functional** programming decomposes a problem into a set of functions. Ideally, functions only take inputs and produce outputs, and ... | some way. Smalltalk and Java are object-oriented languages. C++ and Python are languages that support object-oriented programming, but don't force the use of object-oriented features.
* **Functional** programming decomposes a problem into a set of functions. Ideally, functions only take inputs and produce outputs, and ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
421e1be6-f7d3-4010-9684-61b6e3585d28 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,222 | supabase-export-v2 | 32a1bf510192a8f0 | import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
You can figure it out, but it takes time to disentangle the expression to figure
out what's going on. Using a short nested ``def`` statements makes things a
little bit better:: | trusted_official_docs | CPython Docs | import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
You can figure it out, but it takes time to disentangle the expression to figure
out what's going on. Using a short nested ``def`` statements makes things a
little bit better:: | import functools total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]
You can figure it out, but it takes time to disentangle the expression to figure
out what's going on. Using a short nested ``def`` statements makes things a
little bit better:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4319f124-d232-4d7f-acc3-fd3f34686dac | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,987 | supabase-export-v2 | 55ec0174564dd26b | section explains the basic concept of functional programming; if you're just interested in learning about Python language features, skip to the next section on :ref:`functional-howto-iterators`.
Programming languages support decomposing problems in several different ways: | trusted_official_docs | CPython Docs | section explains the basic concept of functional programming; if you're just interested in learning about Python language features, skip to the next section on :ref:`functional-howto-iterators`.
Programming languages support decomposing problems in several different ways: | section explains the basic concept of functional programming; if you're just interested in learning about Python language features, skip to the next section on :ref:`functional-howto-iterators`.
Programming languages support decomposing problems in several different ways: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
43f005c2-2ff6-4d91-b3a6-f22ec22045db | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,993 | supabase-export-v2 | 6fa948b101b2f8de | large program, different sections might be written using different approaches; the GUI might be object-oriented while the processing logic is procedural or functional, for example.
In a functional program, input flows through a set of functions. Each function
operates on its input and produces some output. Functional s... | trusted_official_docs | CPython Docs | large program, different sections might be written using different approaches; the GUI might be object-oriented while the processing logic is procedural or functional, for example.
In a functional program, input flows through a set of functions. Each function
operates on its input and produces some output. Functional s... | large program, different sections might be written using different approaches; the GUI might be object-oriented while the processing logic is procedural or functional, for example.
In a functional program, input flows through a set of functions. Each function
operates on its input and produces some output. Functional s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44f19ba5-ac0b-4d83-bde0-4c1396847abe | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,002 | supabase-export-v2 | e824e757276b265b | and concluding that the code looks right; the goal is instead a rigorous proof that a program produces the right result for all possible inputs.
The technique used to prove programs correct is to write down **invariants**,
properties of the input data and of the program's variables that are always
true. For each line o... | trusted_official_docs | CPython Docs | and concluding that the code looks right; the goal is instead a rigorous proof that a program produces the right result for all possible inputs.
The technique used to prove programs correct is to write down **invariants**,
properties of the input data and of the program's variables that are always
true. For each line o... | and concluding that the code looks right; the goal is instead a rigorous proof that a program produces the right result for all possible inputs.
The technique used to prove programs correct is to write down **invariants**,
properties of the input data and of the program's variables that are always
true. For each line o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
45cca46f-f928-4bab-b58c-b07221427ffd | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,063 | supabase-export-v2 | 7713c0b0c122caaa | seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE [('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1), ('c', 2), ('c', 3)]
To avoid introducing an ambiguity into Python's grammar, if ``expression`` is
creating a tuple, it must be surrounded with parentheses. The first list
comprehension below is a s... | trusted_official_docs | CPython Docs | seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE [('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1), ('c', 2), ('c', 3)]
To avoid introducing an ambiguity into Python's grammar, if ``expression`` is
creating a tuple, it must be surrounded with parentheses. The first list
comprehension below is a s... | seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE [('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1), ('c', 2), ('c', 3)]
To avoid introducing an ambiguity into Python's grammar, if ``expression`` is
creating a tuple, it must be surrounded with parentheses. The first list
comprehension below is a s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
489f2abe-9bca-4b73-9a40-188cd52dbaa4 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,248 | supabase-export-v2 | 3b126cd071f6b713 | Python-specific ---------------
https://gnosis.cx/TPiP/: The first chapter of David Mertz's book
:title-reference:`Text Processing in Python` discusses functional programming
for text processing, in the section titled "Utilizing Higher-Order Functions in
Text Processing". | trusted_official_docs | CPython Docs | Python-specific ---------------
https://gnosis.cx/TPiP/: The first chapter of David Mertz's book
:title-reference:`Text Processing in Python` discusses functional programming
for text processing, in the section titled "Utilizing Higher-Order Functions in
Text Processing". | Python-specific ---------------
https://gnosis.cx/TPiP/: The first chapter of David Mertz's book
:title-reference:`Text Processing in Python` discusses functional programming
for text processing, in the section titled "Utilizing Higher-Order Functions in
Text Processing". | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
49939598-6c46-46ae-9d42-b92994960ef1 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,188 | supabase-export-v2 | 77e062dd6a0797c3 | **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
For programs written in a functional style, you'll sometimes want to construct
variants of existing functions that have some of the parameters filled ... | trusted_official_docs | CPython Docs | **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
For programs written in a functional style, you'll sometimes want to construct
variants of existing functions that have some of the parameters filled ... | **higher-order function** takes one or more functions as input and returns a new function. The most useful tool in this module is the :func:`functools.partial` function.
For programs written in a functional style, you'll sometimes want to construct
variants of existing functions that have some of the parameters filled ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4c95caa2-ef9c-43a8-b841-fc1d6c4bcdc2 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,051 | supabase-export-v2 | 93177357f8965fe2 | useful if you're working with iterators that return an infinite stream or a very large amount of data. Generator expressions are preferable in these situations.
Generator expressions are surrounded by parentheses ("()") and list
comprehensions are surrounded by square brackets ("[]"). Generator expressions
have the for... | trusted_official_docs | CPython Docs | useful if you're working with iterators that return an infinite stream or a very large amount of data. Generator expressions are preferable in these situations.
Generator expressions are surrounded by parentheses ("()") and list
comprehensions are surrounded by square brackets ("[]"). Generator expressions
have the for... | useful if you're working with iterators that return an infinite stream or a very large amount of data. Generator expressions are preferable in these situations.
Generator expressions are surrounded by parentheses ("()") and list
comprehensions are surrounded by square brackets ("[]"). Generator expressions
have the for... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
50c6978e-7696-4fe3-ad81-4aacf88c5f67 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,241 | supabase-export-v2 | edd27d1334e2a015 | General -------
**Structure and Interpretation of Computer Programs**, by Harold Abelson and
Gerald Jay Sussman with Julie Sussman. The book can be found at
https://mitpress.mit.edu/sicp. In this classic textbook of computer science,
chapters 2 and 3 discuss the use of sequences and streams to organize the data
flow in... | trusted_official_docs | CPython Docs | General -------
**Structure and Interpretation of Computer Programs**, by Harold Abelson and
Gerald Jay Sussman with Julie Sussman. The book can be found at
https://mitpress.mit.edu/sicp. In this classic textbook of computer science,
chapters 2 and 3 discuss the use of sequences and streams to organize the data
flow in... | General -------
**Structure and Interpretation of Computer Programs**, by Harold Abelson and
Gerald Jay Sussman with Julie Sussman. The book can be found at
https://mitpress.mit.edu/sicp. In this classic textbook of computer science,
chapters 2 and 3 discuss the use of sequences and streams to organize the data
flow in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53cd8291-6723-42b4-882d-bb5ee8d6111c | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,139 | supabase-export-v2 | d12bf6107e956fcf | itertools.repeat('abc') => abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) => abc, abc, abc, abc, abc
:func:`itertools.chain(iterA, iterB, ...) <itertools.chain>` takes an arbitrary
number of iterables as input, and returns all the elements of the first
iterator, then all the elements o... | trusted_official_docs | CPython Docs | itertools.repeat('abc') => abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) => abc, abc, abc, abc, abc
:func:`itertools.chain(iterA, iterB, ...) <itertools.chain>` takes an arbitrary
number of iterables as input, and returns all the elements of the first
iterator, then all the elements o... | itertools.repeat('abc') => abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ... itertools.repeat('abc', 5) => abc, abc, abc, abc, abc
:func:`itertools.chain(iterA, iterB, ...) <itertools.chain>` takes an arbitrary
number of iterables as input, and returns all the elements of the first
iterator, then all the elements o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
546d89d9-a403-4fdc-bb2e-a00872875036 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,061 | supabase-export-v2 | df54f1f8c2e1c35d | # Output the value of # the expression.
This means that when there are multiple ``for...in`` clauses but no ``if``
clauses, the length of the resulting output will be equal to the product of the
lengths of all the sequences. If you have two lists of length 3, the output
list is 9 elements long: | trusted_official_docs | CPython Docs | # Output the value of # the expression.
This means that when there are multiple ``for...in`` clauses but no ``if``
clauses, the length of the resulting output will be equal to the product of the
lengths of all the sequences. If you have two lists of length 3, the output
list is 9 elements long: | # Output the value of # the expression.
This means that when there are multiple ``for...in`` clauses but no ``if``
clauses, the length of the resulting output will be equal to the product of the
lengths of all the sequences. If you have two lists of length 3, the output
list is 9 elements long: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
558008a5-6200-4508-adba-a03fa2fe1a28 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,178 | supabase-export-v2 | eb9ac76d0ec97019 | Grouping elements -----------------
The last function I'll discuss, :func:`itertools.groupby(iter, key_func=None)
<itertools.groupby>`, is the most complicated. ``key_func(elem)`` is a function
that can compute a key value for each element returned by the iterable. If you
don't supply a key function, the key is simply ... | trusted_official_docs | CPython Docs | Grouping elements -----------------
The last function I'll discuss, :func:`itertools.groupby(iter, key_func=None)
<itertools.groupby>`, is the most complicated. ``key_func(elem)`` is a function
that can compute a key value for each element returned by the iterable. If you
don't supply a key function, the key is simply ... | Grouping elements -----------------
The last function I'll discuss, :func:`itertools.groupby(iter, key_func=None)
<itertools.groupby>`, is the most complicated. ``key_func(elem)`` is a function
that can compute a key value for each element returned by the iterable. If you
don't supply a key function, the key is simply ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
56b3e8de-4c24-4833-9d5c-f2754e307ad9 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,058 | supabase-export-v2 | af37d89f91caf432 | element in ``sequence1``, ``sequence2`` is looped over from the beginning. ``sequence3`` is then looped over for each resulting pair of elements from ``sequence1`` and ``sequence2``.
To put it another way, a list comprehension or generator expression is
equivalent to the following Python code:: | trusted_official_docs | CPython Docs | element in ``sequence1``, ``sequence2`` is looped over from the beginning. ``sequence3`` is then looped over for each resulting pair of elements from ``sequence1`` and ``sequence2``.
To put it another way, a list comprehension or generator expression is
equivalent to the following Python code:: | element in ``sequence1``, ``sequence2`` is looped over from the beginning. ``sequence3`` is then looped over for each resulting pair of elements from ``sequence1`` and ``sequence2``.
To put it another way, a list comprehension or generator expression is
equivalent to the following Python code:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
579f1bc4-2a72-49b7-bb97-cf2b6fdcf92b | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,053 | supabase-export-v2 | 483e1204ba6d65b1 | expr in sequence1 if condition1 for expr2 in sequence2 if condition2 for expr3 in sequence3 if condition3 ... for exprN in sequenceN if conditionN )
Again, for a list comprehension only the outside brackets are different (square
brackets instead of parentheses). | trusted_official_docs | CPython Docs | expr in sequence1 if condition1 for expr2 in sequence2 if condition2 for expr3 in sequence3 if condition3 ... for exprN in sequenceN if conditionN )
Again, for a list comprehension only the outside brackets are different (square
brackets instead of parentheses). | expr in sequence1 if condition1 for expr2 in sequence2 if condition2 for expr3 in sequence3 if condition3 ... for exprN in sequenceN if conditionN )
Again, for a list comprehension only the outside brackets are different (square
brackets instead of parentheses). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
58510792-9d89-4465-b0f2-a81b72e807a4 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,124 | supabase-export-v2 | eb57e1c7d7cb8519 | zip(['a', 'b', 'c'], (1, 2, 3)) => ('a', 1), ('b', 2), ('c', 3)
It doesn't construct an in-memory list and exhaust all the input iterators
before returning; instead tuples are constructed and returned only if they're
requested. (The technical term for this behaviour is `lazy evaluation
<https://en.wikipedia.org/wiki/La... | trusted_official_docs | CPython Docs | zip(['a', 'b', 'c'], (1, 2, 3)) => ('a', 1), ('b', 2), ('c', 3)
It doesn't construct an in-memory list and exhaust all the input iterators
before returning; instead tuples are constructed and returned only if they're
requested. (The technical term for this behaviour is `lazy evaluation
<https://en.wikipedia.org/wiki/La... | zip(['a', 'b', 'c'], (1, 2, 3)) => ('a', 1), ('b', 2), ('c', 3)
It doesn't construct an in-memory list and exhaust all the input iterators
before returning; instead tuples are constructed and returned only if they're
requested. (The technical term for this behaviour is `lazy evaluation
<https://en.wikipedia.org/wiki/La... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a541a77-8fd9-4329-85e7-6be177ef668b | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,150 | supabase-export-v2 | 67c7c71571f1cb23 | :func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the iterable will return a stream of tuples, and calls *func* using these tuples as the arguments::
itertools.starmap(os.path.join,
[('/bin', 'python'), ('/usr', 'bin', 'java'),
('/usr', 'bin', 'perl'), ('/usr', 'bin', 'ruby')])
=>
/bin/python, ... | trusted_official_docs | CPython Docs | :func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the iterable will return a stream of tuples, and calls *func* using these tuples as the arguments::
itertools.starmap(os.path.join,
[('/bin', 'python'), ('/usr', 'bin', 'java'),
('/usr', 'bin', 'perl'), ('/usr', 'bin', 'ruby')])
=>
/bin/python, ... | :func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the iterable will return a stream of tuples, and calls *func* using these tuples as the arguments::
itertools.starmap(os.path.join,
[('/bin', 'python'), ('/usr', 'bin', 'java'),
('/usr', 'bin', 'perl'), ('/usr', 'bin', 'ruby')])
=>
/bin/python, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
610e34f6-2a0e-48a3-a5cc-f729275686f8 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,094 | supabase-export-v2 | 83d62900b44929f3 | #doctest: +SKIP 8 >>> next(it) #doctest: +SKIP 9 >>> next(it) #doctest: +SKIP Traceback (most recent call last): File "t.py", line 15, in <module> it.next() StopIteration
Because ``yield`` will often be returning ``None``, you should always check for
this case. Don't just use its value in expressions unless you're sure... | trusted_official_docs | CPython Docs | #doctest: +SKIP 8 >>> next(it) #doctest: +SKIP 9 >>> next(it) #doctest: +SKIP Traceback (most recent call last): File "t.py", line 15, in <module> it.next() StopIteration
Because ``yield`` will often be returning ``None``, you should always check for
this case. Don't just use its value in expressions unless you're sure... | #doctest: +SKIP 8 >>> next(it) #doctest: +SKIP 9 >>> next(it) #doctest: +SKIP Traceback (most recent call last): File "t.py", line 15, in <module> it.next() StopIteration
Because ``yield`` will often be returning ``None``, you should always check for
this case. Don't just use its value in expressions unless you're sure... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
629c88fa-b1f6-4ed4-a90e-00c22814302a | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,171 | supabase-export-v2 | c92755b8b68f2817 | 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
If you don't supply a value for *r* the length of the iterable is used,
meaning that all the elements are permuted. | trusted_official_docs | CPython Docs | 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
If you don't supply a value for *r* the length of the iterable is used,
meaning that all the elements are permuted. | 3, 4, 5]) => (1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), ... (5, 4, 3, 2, 1)
If you don't supply a value for *r* the length of the iterable is used,
meaning that all the elements are permuted. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62a05afe-0550-4315-b3f3-92280b1d2d49 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,135 | supabase-export-v2 | faacf3a841ba259f | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) => 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, ...
:func:`itertools.cycle(iter) <itertools.cycle>` saves a copy of the contents of
a provided iterable and returns a new iterator that returns its elements from
first to last. The new iterator will repeat thes... | trusted_official_docs | CPython Docs | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) => 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, ...
:func:`itertools.cycle(iter) <itertools.cycle>` saves a copy of the contents of
a provided iterable and returns a new iterator that returns its elements from
first to last. The new iterator will repeat thes... | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) => 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, ...
:func:`itertools.cycle(iter) <itertools.cycle>` saves a copy of the contents of
a provided iterable and returns a new iterator that returns its elements from
first to last. The new iterator will repeat thes... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62e06946-9953-489f-9805-75a79a66d698 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,039 | supabase-export-v2 | e27112ccf30b1f37 | calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a file like this::
for line in file:
# do something for each line
... | trusted_official_docs | CPython Docs | calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a file like this::
for line in file:
# do something for each line
... | calling the :meth:`~io.TextIOBase.readline` method until there are no more lines in the file. This means you can read each line of a file like this::
for line in file:
# do something for each line
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62ee2980-d99e-4faa-bd7a-d834c87bfc7c | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,115 | supabase-export-v2 | ad6722b2fec39d4f | >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
:func:`enumerate` is often used when looping through a list and recording the
indexes at which certain conditions are met:: | trusted_official_docs | CPython Docs | >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
:func:`enumerate` is often used when looping through a list and recording the
indexes at which certain conditions are met:: | >>> for item in enumerate(['subject', 'verb', 'object']): ... print(item) (0, 'subject') (1, 'verb') (2, 'object')
:func:`enumerate` is often used when looping through a list and recording the
indexes at which certain conditions are met:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
63528ece-3b3e-4d6a-9ffb-be52ef5f0d6b | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,034 | supabase-export-v2 | bd88f838bbbef636 | m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
Note that starting with Python 3.7, dictionary iteration order is guaranteed
to be the same as the insertion order. In earlier versions, the behaviour was
unspecified and could vary between implementations. | trusted_official_docs | CPython Docs | m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
Note that starting with Python 3.7, dictionary iteration order is guaranteed
to be the same as the insertion order. In earlier versions, the behaviour was
unspecified and could vary between implementations. | m[key]) Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
Note that starting with Python 3.7, dictionary iteration order is guaranteed
to be the same as the insertion order. In earlier versions, the behaviour was
unspecified and could vary between implementations. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
63688d0f-1144-4433-b189-a10fdda0e04d | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,050 | supabase-export-v2 | ff91f6c7fde75eb2 | >>> stripped_list = [line.strip() for line in line_list ... if line != ""]
With a list comprehension, you get back a Python list; ``stripped_list`` is a
list containing the resulting lines, not an iterator. Generator expressions
return an iterator that computes the values as necessary, not needing to
materialize all th... | trusted_official_docs | CPython Docs | >>> stripped_list = [line.strip() for line in line_list ... if line != ""]
With a list comprehension, you get back a Python list; ``stripped_list`` is a
list containing the resulting lines, not an iterator. Generator expressions
return an iterator that computes the values as necessary, not needing to
materialize all th... | >>> stripped_list = [line.strip() for line in line_list ... if line != ""]
With a list comprehension, you get back a Python list; ``stripped_list`` is a
list containing the resulting lines, not an iterator. Generator expressions
return an iterator that computes the values as necessary, not needing to
materialize all th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64459325-dec1-42e2-9fcf-e5d853c48e61 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,073 | supabase-export-v2 | 3a88788f5994b709 | Here's a sample usage of the ``generate_ints()`` generator:
>>> gen = generate_ints(3)
>>> gen #doctest: +ELLIPSIS
<generator object generate_ints at ...>
>>> next(gen)
0
>>> next(gen)
1
>>> next(gen)
2
>>> next(gen)
Traceback (most recent call last):
File "stdin", line 1, in <module>
File "stdin", line 2, ... | trusted_official_docs | CPython Docs | Here's a sample usage of the ``generate_ints()`` generator:
>>> gen = generate_ints(3)
>>> gen #doctest: +ELLIPSIS
<generator object generate_ints at ...>
>>> next(gen)
0
>>> next(gen)
1
>>> next(gen)
2
>>> next(gen)
Traceback (most recent call last):
File "stdin", line 1, in <module>
File "stdin", line 2, ... | Here's a sample usage of the ``generate_ints()`` generator:
>>> gen = generate_ints(3)
>>> gen #doctest: +ELLIPSIS
<generator object generate_ints at ...>
>>> next(gen)
0
>>> next(gen)
1
>>> next(gen)
2
>>> next(gen)
Traceback (most recent call last):
File "stdin", line 1, in <module>
File "stdin", line 2, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
65d06b6c-f6e0-4aff-8c3d-a3a44f79c583 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,195 | supabase-export-v2 | 80bfab35c2a2df2d | a :exc:`TypeError` exception is raised. If the initial value is supplied, it's used as a starting point and ``func(initial_value, A)`` is the first calculation. ::
>>> import operator, functools
>>> functools.reduce(operator.concat, ['A', 'BB', 'C'])
'ABBC'
>>> functools.reduce(operator.concat, [])
Traceback (most ... | trusted_official_docs | CPython Docs | a :exc:`TypeError` exception is raised. If the initial value is supplied, it's used as a starting point and ``func(initial_value, A)`` is the first calculation. ::
>>> import operator, functools
>>> functools.reduce(operator.concat, ['A', 'BB', 'C'])
'ABBC'
>>> functools.reduce(operator.concat, [])
Traceback (most ... | a :exc:`TypeError` exception is raised. If the initial value is supplied, it's used as a starting point and ``func(initial_value, A)`` is the first calculation. ::
>>> import operator, functools
>>> functools.reduce(operator.concat, ['A', 'BB', 'C'])
'ABBC'
>>> functools.reduce(operator.concat, [])
Traceback (most ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
65d80123-0bfe-40ea-a396-48e62dacf0bf | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,044 | supabase-export-v2 | c1d8b10ef759ae30 | given a list of strings, you might want to strip off trailing whitespace from each line or extract all the strings containing a given substring.
List comprehensions and generator expressions (short form: "listcomps" and
"genexps") are a concise notation for such operations, borrowed from the
functional programming lang... | trusted_official_docs | CPython Docs | given a list of strings, you might want to strip off trailing whitespace from each line or extract all the strings containing a given substring.
List comprehensions and generator expressions (short form: "listcomps" and
"genexps") are a concise notation for such operations, borrowed from the
functional programming lang... | given a list of strings, you might want to strip off trailing whitespace from each line or extract all the strings containing a given substring.
List comprehensions and generator expressions (short form: "listcomps" and
"genexps") are a concise notation for such operations, borrowed from the
functional programming lang... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6621de4e-9a71-4bf2-9394-7f2c1fcc427f | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,074 | supabase-export-v2 | 5f8f51ac40584558 | next(gen) 1 >>> next(gen) 2 >>> next(gen) Traceback (most recent call last): File "stdin", line 1, in <module> File "stdin", line 2, in generate_ints StopIteration
You could equally write ``for i in generate_ints(5)``, or ``a, b, c =
generate_ints(3)``. | trusted_official_docs | CPython Docs | next(gen) 1 >>> next(gen) 2 >>> next(gen) Traceback (most recent call last): File "stdin", line 1, in <module> File "stdin", line 2, in generate_ints StopIteration
You could equally write ``for i in generate_ints(5)``, or ``a, b, c =
generate_ints(3)``. | next(gen) 1 >>> next(gen) 2 >>> next(gen) Traceback (most recent call last): File "stdin", line 1, in <module> File "stdin", line 2, in generate_ints StopIteration
You could equally write ``for i in generate_ints(5)``, or ``a, b, c =
generate_ints(3)``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
66db7943-3689-4d9e-9118-b19f6d9685f2 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,127 | supabase-export-v2 | a6aab98582eef094 | zip(['a', 'b'], (1, 2, 3)) => ('a', 1), ('b', 2)
You should avoid doing this, though, because an element may be taken from the
longer iterators and discarded. This means you can't go on to use the iterators
further because you risk skipping a discarded element. | trusted_official_docs | CPython Docs | zip(['a', 'b'], (1, 2, 3)) => ('a', 1), ('b', 2)
You should avoid doing this, though, because an element may be taken from the
longer iterators and discarded. This means you can't go on to use the iterators
further because you risk skipping a discarded element. | zip(['a', 'b'], (1, 2, 3)) => ('a', 1), ('b', 2)
You should avoid doing this, though, because an element may be taken from the
longer iterators and discarded. This means you can't go on to use the iterators
further because you risk skipping a discarded element. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
672851ad-9094-49e7-a5ab-f2bff09398a5 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,060 | supabase-export-v2 | 69fd0ddfd5b6bd6a | for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): continue # Skip this element
# Output the value of
# the expression. | trusted_official_docs | CPython Docs | for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): continue # Skip this element
# Output the value of
# the expression. | for expr2 in sequence2: if not (condition2): continue # Skip this element ... for exprN in sequenceN: if not (conditionN): continue # Skip this element
# Output the value of
# the expression. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
675a99e2-5917-4a28-aaa1-1d2b9e751a3f | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,206 | supabase-export-v2 | aacd8466904ce93f | corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
Some of the functions in this module are: | trusted_official_docs | CPython Docs | corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
Some of the functions in this module are: | corresponding to Python's operators. These functions are often useful in functional-style code because they save you from writing trivial functions that perform a single operation.
Some of the functions in this module are: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6a24c647-52ef-4e4b-b387-d48a760154b9 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,071 | supabase-export-v2 | a10828a79b7bcc8b | Any function containing a :keyword:`yield` keyword is a generator function; this is detected by Python's :term:`bytecode` compiler which compiles the function specially as a result.
When you call a generator function, it doesn't return a single value; instead it
returns a generator object that supports the iterator pro... | trusted_official_docs | CPython Docs | Any function containing a :keyword:`yield` keyword is a generator function; this is detected by Python's :term:`bytecode` compiler which compiles the function specially as a result.
When you call a generator function, it doesn't return a single value; instead it
returns a generator object that supports the iterator pro... | Any function containing a :keyword:`yield` keyword is a generator function; this is detected by Python's :term:`bytecode` compiler which compiles the function specially as a result.
When you call a generator function, it doesn't return a single value; instead it
returns a generator object that supports the iterator pro... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6a4f7e27-ec57-4a9a-994f-928b2953e97d | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,036 | supabase-export-v2 | c8a28d5e2a798d15 | iterators. If you want to iterate over values or key/value pairs, you can explicitly call the :meth:`~dict.values` or :meth:`~dict.items` methods to get an appropriate iterator.
The :func:`dict` constructor can accept an iterator that returns a finite stream
of ``(key, value)`` tuples: | trusted_official_docs | CPython Docs | iterators. If you want to iterate over values or key/value pairs, you can explicitly call the :meth:`~dict.values` or :meth:`~dict.items` methods to get an appropriate iterator.
The :func:`dict` constructor can accept an iterator that returns a finite stream
of ``(key, value)`` tuples: | iterators. If you want to iterate over values or key/value pairs, you can explicitly call the :meth:`~dict.values` or :meth:`~dict.items` methods to get an appropriate iterator.
The :func:`dict` constructor can accept an iterator that returns a finite stream
of ``(key, value)`` tuples: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6a5d2d33-3367-47b1-89a2-79fac2384e14 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,095 | supabase-export-v2 | 4da335a3cf65d428 | Don't just use its value in expressions unless you're sure that the :meth:`~generator.send` method will be the only method used to resume your generator function.
In addition to :meth:`~generator.send`, there are two other methods on
generators: | trusted_official_docs | CPython Docs | Don't just use its value in expressions unless you're sure that the :meth:`~generator.send` method will be the only method used to resume your generator function.
In addition to :meth:`~generator.send`, there are two other methods on
generators: | Don't just use its value in expressions unless you're sure that the :meth:`~generator.send` method will be the only method used to resume your generator function.
In addition to :meth:`~generator.send`, there are two other methods on
generators: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e1fd864-f4ec-4d4f-87e2-1072915ad837 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,062 | supabase-export-v2 | c43b3f2afef21553 | to the product of the lengths of all the sequences. If you have two lists of length 3, the output list is 9 elements long:
>>> seq1 = 'abc'
>>> seq2 = (1, 2, 3)
>>> [(x, y) for x in seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE
[('a', 1), ('a', 2), ('a', 3),
('b', 1), ('b', 2), ('b', 3),
('c', 1), ('c', 2), ... | trusted_official_docs | CPython Docs | to the product of the lengths of all the sequences. If you have two lists of length 3, the output list is 9 elements long:
>>> seq1 = 'abc'
>>> seq2 = (1, 2, 3)
>>> [(x, y) for x in seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE
[('a', 1), ('a', 2), ('a', 3),
('b', 1), ('b', 2), ('b', 3),
('c', 1), ('c', 2), ... | to the product of the lengths of all the sequences. If you have two lists of length 3, the output list is 9 elements long:
>>> seq1 = 'abc'
>>> seq2 = (1, 2, 3)
>>> [(x, y) for x in seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE
[('a', 1), ('a', 2), ('a', 3),
('b', 1), ('b', 2), ('b', 3),
('c', 1), ('c', 2), ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e3b4580-9b76-4013-9901-460e4d62ef79 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,056 | supabase-export-v2 | 0ef98e9f5fa4e8ae | parentheses signalling a function call also count. If you want to create an iterator that will be immediately passed to a function you can write::
obj_total = sum(obj.count for obj in list_all_objects()) | trusted_official_docs | CPython Docs | parentheses signalling a function call also count. If you want to create an iterator that will be immediately passed to a function you can write::
obj_total = sum(obj.count for obj in list_all_objects()) | parentheses signalling a function call also count. If you want to create an iterator that will be immediately passed to a function you can write::
obj_total = sum(obj.count for obj in list_all_objects()) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6f1ef590-836a-4ce4-a9a2-013f73fbcc12 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,018 | supabase-export-v2 | 8bc3b4ced1614001 | raise the :exc:`StopIteration` exception. Iterators don't have to be finite, though; it's perfectly reasonable to write an iterator that produces an infinite stream of data.
The built-in :func:`iter` function takes an arbitrary object and tries to return
an iterator that will return the object's contents or elements, r... | trusted_official_docs | CPython Docs | raise the :exc:`StopIteration` exception. Iterators don't have to be finite, though; it's perfectly reasonable to write an iterator that produces an infinite stream of data.
The built-in :func:`iter` function takes an arbitrary object and tries to return
an iterator that will return the object's contents or elements, r... | raise the :exc:`StopIteration` exception. Iterators don't have to be finite, though; it's perfectly reasonable to write an iterator that produces an infinite stream of data.
The built-in :func:`iter` function takes an arbitrary object and tries to return
an iterator that will return the object's contents or elements, r... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6f6ff93c-1011-4bcb-ac9a-4cc380517694 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,009 | supabase-export-v2 | cac44e00e5c43d05 | Testing and debugging a functional-style program is easier.
Debugging is simplified because functions are generally small and clearly
specified. When a program doesn't work, each function is an interface point
where you can check that the data are correct. You can look at the intermediate
inputs and outputs to quickly ... | trusted_official_docs | CPython Docs | Testing and debugging a functional-style program is easier.
Debugging is simplified because functions are generally small and clearly
specified. When a program doesn't work, each function is an interface point
where you can check that the data are correct. You can look at the intermediate
inputs and outputs to quickly ... | Testing and debugging a functional-style program is easier.
Debugging is simplified because functions are generally small and clearly
specified. When a program doesn't work, each function is an interface point
where you can check that the data are correct. You can look at the intermediate
inputs and outputs to quickly ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6feabc89-5049-483a-9e2a-fd67c73ff0c5 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,006 | supabase-export-v2 | ca4a0cf6949583e4 | Modularity ----------
A more practical benefit of functional programming is that it forces you to
break apart your problem into small pieces. Programs are more modular as a
result. It's easier to specify and write a small function that does one thing
than a large function that performs a complicated transformation. Sma... | trusted_official_docs | CPython Docs | Modularity ----------
A more practical benefit of functional programming is that it forces you to
break apart your problem into small pieces. Programs are more modular as a
result. It's easier to specify and write a small function that does one thing
than a large function that performs a complicated transformation. Sma... | Modularity ----------
A more practical benefit of functional programming is that it forces you to
break apart your problem into small pieces. Programs are more modular as a
result. It's easier to specify and write a small function that does one thing
than a large function that performs a complicated transformation. Sma... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
72a174a9-7842-4ef1-aabb-27945772d52a | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,116 | supabase-export-v2 | 0163874229b5d0f9 | :func:`enumerate` is often used when looping through a list and recording the indexes at which certain conditions are met::
f = open('data.txt', 'r')
for i, line in enumerate(f):
if line.strip() == '':
print('Blank line at line #%i' % i) | trusted_official_docs | CPython Docs | :func:`enumerate` is often used when looping through a list and recording the indexes at which certain conditions are met::
f = open('data.txt', 'r')
for i, line in enumerate(f):
if line.strip() == '':
print('Blank line at line #%i' % i) | :func:`enumerate` is often used when looping through a list and recording the indexes at which certain conditions are met::
f = open('data.txt', 'r')
for i, line in enumerate(f):
if line.strip() == '':
print('Blank line at line #%i' % i) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
72a548d3-1873-42a5-a394-0b643e263504 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,163 | supabase-export-v2 | 9b3f6cc16e8096cf | takes two iterators and returns only those elements of *data* for which the corresponding element of *selectors* is true, stopping whenever either one is exhausted::
itertools.compress([1, 2, 3, 4, 5], [True, True, False, False, True]) =>
1, 2, 5 | trusted_official_docs | CPython Docs | takes two iterators and returns only those elements of *data* for which the corresponding element of *selectors* is true, stopping whenever either one is exhausted::
itertools.compress([1, 2, 3, 4, 5], [True, True, False, False, True]) =>
1, 2, 5 | takes two iterators and returns only those elements of *data* for which the corresponding element of *selectors* is true, stopping whenever either one is exhausted::
itertools.compress([1, 2, 3, 4, 5], [True, True, False, False, True]) =>
1, 2, 5 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
72a6a1bb-7726-47ae-b2c8-6c7e796dd0a9 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,091 | supabase-export-v2 | 81c4b3cc289a86c2 | .. testcode::
def counter(maximum):
i = 0
while i < maximum:
val = (yield i)
# If value provided, change counter
if val is not None:
i = val
else:
i += 1 | trusted_official_docs | CPython Docs | .. testcode::
def counter(maximum):
i = 0
while i < maximum:
val = (yield i)
# If value provided, change counter
if val is not None:
i = val
else:
i += 1 | .. testcode::
def counter(maximum):
i = 0
while i < maximum:
val = (yield i)
# If value provided, change counter
if val is not None:
i = val
else:
i += 1 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
731877e6-b804-4b0b-b4d9-e5821e675010 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,988 | supabase-export-v2 | 5791f3ffb102502f | Programming languages support decomposing problems in several different ways:
* Most programming languages are **procedural**: programs are lists of
instructions that tell the computer what to do with the program's input. C,
Pascal, and even Unix shells are procedural languages. | trusted_official_docs | CPython Docs | Programming languages support decomposing problems in several different ways:
* Most programming languages are **procedural**: programs are lists of
instructions that tell the computer what to do with the program's input. C,
Pascal, and even Unix shells are procedural languages. | Programming languages support decomposing problems in several different ways:
* Most programming languages are **procedural**: programs are lists of
instructions that tell the computer what to do with the program's input. C,
Pascal, and even Unix shells are procedural languages. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
73f105fa-d329-4853-a5cf-364b1c2f3b12 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,004 | supabase-export-v2 | 2ed3948372cfee7d | to handle with this technique; assignments can break invariants that were true before the assignment without producing any new invariants that can be propagated onward.
Unfortunately, proving programs correct is largely impractical and not relevant
to Python software. Even trivial programs require proofs that are sever... | trusted_official_docs | CPython Docs | to handle with this technique; assignments can break invariants that were true before the assignment without producing any new invariants that can be propagated onward.
Unfortunately, proving programs correct is largely impractical and not relevant
to Python software. Even trivial programs require proofs that are sever... | to handle with this technique; assignments can break invariants that were true before the assignment without producing any new invariants that can be propagated onward.
Unfortunately, proving programs correct is largely impractical and not relevant
to Python software. Even trivial programs require proofs that are sever... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
74d9bb5d-b4ac-4a6d-b086-406d27083e82 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,003 | supabase-export-v2 | 46313d1d6e890aac | executed. This continues until you reach the end of the program, at which point the invariants should match the desired conditions on the program's output.
Functional programming's avoidance of assignments arose because assignments are
difficult to handle with this technique; assignments can break invariants that
were ... | trusted_official_docs | CPython Docs | executed. This continues until you reach the end of the program, at which point the invariants should match the desired conditions on the program's output.
Functional programming's avoidance of assignments arose because assignments are
difficult to handle with this technique; assignments can break invariants that
were ... | executed. This continues until you reach the end of the program, at which point the invariants should match the desired conditions on the program's output.
Functional programming's avoidance of assignments arose because assignments are
difficult to handle with this technique; assignments can break invariants that
were ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
75d658fe-64cb-46fe-8fbb-4bd79ed4a065 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,096 | supabase-export-v2 | 1bb2423d1c1f17f0 | In addition to :meth:`~generator.send`, there are two other methods on generators:
* :meth:`throw(value) <generator.throw>` is used to
raise an exception inside the generator; the exception is raised by the
``yield`` expression where the generator's execution is paused. | trusted_official_docs | CPython Docs | In addition to :meth:`~generator.send`, there are two other methods on generators:
* :meth:`throw(value) <generator.throw>` is used to
raise an exception inside the generator; the exception is raised by the
``yield`` expression where the generator's execution is paused. | In addition to :meth:`~generator.send`, there are two other methods on generators:
* :meth:`throw(value) <generator.throw>` is used to
raise an exception inside the generator; the exception is raised by the
``yield`` expression where the generator's execution is paused. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77747881-4ff2-408b-a0df-161a2fea2357 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,174 | supabase-export-v2 | c3434e9e0aed785e | itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a'
strings came from different positions. | trusted_official_docs | CPython Docs | itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a'
strings came from different positions. | itertools.permutations('aba', 3) => ('a', 'b', 'a'), ('a', 'a', 'b'), ('b', 'a', 'a'), ('b', 'a', 'a'), ('a', 'a', 'b'), ('a', 'b', 'a')
The identical tuple ``('a', 'a', 'b')`` occurs twice, but the two 'a'
strings came from different positions. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
79b9129e-9ac5-4467-aa50-489431b2ac87 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,149 | supabase-export-v2 | 00aaaec4bd8f9d6c | :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrgetter('id') <operator.attrgetter>` (returns a callable that fetches the ``.id`` attribute).
:func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the
itera... | trusted_official_docs | CPython Docs | :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrgetter('id') <operator.attrgetter>` (returns a callable that fetches the ``.id`` attribute).
:func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the
itera... | :func:`operator.add(a, b) <operator.add>` (adds two values), :func:`operator.ne(a, b) <operator.ne>` (same as ``a != b``), and :func:`operator.attrgetter('id') <operator.attrgetter>` (returns a callable that fetches the ``.id`` attribute).
:func:`itertools.starmap(func, iter) <itertools.starmap>` assumes that the
itera... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7c28f667-c69e-4cd1-bbe4-5b19182c2882 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,092 | supabase-export-v2 | 172eea4cde99f34d | i < maximum: val = (yield i) # If value provided, change counter if val is not None: i = val else: i += 1
And here's an example of changing the counter: | trusted_official_docs | CPython Docs | i < maximum: val = (yield i) # If value provided, change counter if val is not None: i = val else: i += 1
And here's an example of changing the counter: | i < maximum: val = (yield i) # If value provided, change counter if val is not None: i = val else: i += 1
And here's an example of changing the counter: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d44e8df-5048-4ffa-b365-528cb7f5e625 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,185 | supabase-export-v2 | 9f1291f6665ece3b | where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
:func:`~itertools.groupby` assumes that the underlying iterable's contents will
already be sorted based on the key. Note t... | trusted_official_docs | CPython Docs | where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
:func:`~itertools.groupby` assumes that the underlying iterable's contents will
already be sorted based on the key. Note t... | where iterator-1 => ('Decatur', 'AL'), ('Huntsville', 'AL'), ('Selma', 'AL') iterator-2 => ('Anchorage', 'AK'), ('Nome', 'AK') iterator-3 => ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')
:func:`~itertools.groupby` assumes that the underlying iterable's contents will
already be sorted based on the key. Note t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d53e98d-0f32-4840-9f36-0fe9a9674a79 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,134 | supabase-export-v2 | 20cefde67c9801e1 | stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
itertools.count() =>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... itertools.count(10) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) =>
10, 15, 20, 2... | trusted_official_docs | CPython Docs | stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
itertools.count() =>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... itertools.count(10) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) =>
10, 15, 20, 2... | stream of evenly spaced values. You can optionally supply the starting number, which defaults to 0, and the interval between numbers, which defaults to 1::
itertools.count() =>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... itertools.count(10) =>
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ... itertools.count(10, 5) =>
10, 15, 20, 2... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7e671558-5386-4527-93fa-ddbfca7a6a8f | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,109 | supabase-export-v2 | 9f8a16099cbeef66 | comprehensions. A **predicate** is a function that returns the truth value of some condition; for use with :func:`filter`, the predicate must take a single value.
>>> def is_even(x):
... return (x % 2) == 0 | trusted_official_docs | CPython Docs | comprehensions. A **predicate** is a function that returns the truth value of some condition; for use with :func:`filter`, the predicate must take a single value.
>>> def is_even(x):
... return (x % 2) == 0 | comprehensions. A **predicate** is a function that returns the truth value of some condition; for use with :func:`filter`, the predicate must take a single value.
>>> def is_even(x):
... return (x % 2) == 0 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7ef28b0c-c71b-4544-b454-6d9c2afd2aa5 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,037 | supabase-export-v2 | 1cad6496c17aec3d | The :func:`dict` constructor can accept an iterator that returns a finite stream of ``(key, value)`` tuples:
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
>>> dict(iter(L))
{'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} | trusted_official_docs | CPython Docs | The :func:`dict` constructor can accept an iterator that returns a finite stream of ``(key, value)`` tuples:
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
>>> dict(iter(L))
{'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} | The :func:`dict` constructor can accept an iterator that returns a finite stream of ``(key, value)`` tuples:
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
>>> dict(iter(L))
{'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
803b457a-e79f-4cdb-bb4e-bb0aa6408b39 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,190 | supabase-export-v2 | f4479cd51a18741b | arguments ``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting object is callable, so you can just call it to invoke ``function`` with the filled-in arguments.
Here's a small but realistic example:: | trusted_official_docs | CPython Docs | arguments ``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting object is callable, so you can just call it to invoke ``function`` with the filled-in arguments.
Here's a small but realistic example:: | arguments ``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting object is callable, so you can just call it to invoke ``function`` with the filled-in arguments.
Here's a small but realistic example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
81aa1afb-5020-4352-a1b5-4c3566befe2f | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,189 | supabase-export-v2 | 20d9307b9d6e449a | function ``g(b, c)`` that's equivalent to ``f(1, b, c)``; you're filling in a value for one of ``f()``'s parameters. This is called "partial function application".
The constructor for :func:`~functools.partial` takes the arguments
``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting
object is ca... | trusted_official_docs | CPython Docs | function ``g(b, c)`` that's equivalent to ``f(1, b, c)``; you're filling in a value for one of ``f()``'s parameters. This is called "partial function application".
The constructor for :func:`~functools.partial` takes the arguments
``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting
object is ca... | function ``g(b, c)`` that's equivalent to ``f(1, b, c)``; you're filling in a value for one of ``f()``'s parameters. This is called "partial function application".
The constructor for :func:`~functools.partial` takes the arguments
``(function, arg1, arg2, ..., kwarg1=value1, kwarg2=value2)``. The resulting
object is ca... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
85063c7a-39c3-4e74-82c4-1a1923134595 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,045 | supabase-export-v2 | aa7e4cee104d9ef5 | such operations, borrowed from the functional programming language Haskell (https://www.haskell.org/). You can strip all the whitespace from a stream of strings with the following code::
>>> line_list = [' line 1\n', 'line 2 \n', ' \n', ''] | trusted_official_docs | CPython Docs | such operations, borrowed from the functional programming language Haskell (https://www.haskell.org/). You can strip all the whitespace from a stream of strings with the following code::
>>> line_list = [' line 1\n', 'line 2 \n', ' \n', ''] | such operations, borrowed from the functional programming language Haskell (https://www.haskell.org/). You can strip all the whitespace from a stream of strings with the following code::
>>> line_list = [' line 1\n', 'line 2 \n', ' \n', ''] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
85aed907-2a0b-484f-81f1-59cefeeeb505 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,054 | supabase-export-v2 | 5fda39b17ef3e25f | Again, for a list comprehension only the outside brackets are different (square brackets instead of parentheses).
The elements of the generated output will be the successive values of
``expression``. The ``if`` clauses are all optional; if present, ``expression``
is only evaluated and added to the result when ``conditi... | trusted_official_docs | CPython Docs | Again, for a list comprehension only the outside brackets are different (square brackets instead of parentheses).
The elements of the generated output will be the successive values of
``expression``. The ``if`` clauses are all optional; if present, ``expression``
is only evaluated and added to the result when ``conditi... | Again, for a list comprehension only the outside brackets are different (square brackets instead of parentheses).
The elements of the generated output will be the successive values of
``expression``. The ``if`` clauses are all optional; if present, ``expression``
is only evaluated and added to the result when ``conditi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
863a417c-557e-43b4-97b2-38f6f6cffa40 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,137 | supabase-export-v2 | 97a369d56c44b303 | itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
:func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided
element *n* times, or returns the element endlessly if *n* is not provided. :: | trusted_official_docs | CPython Docs | itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
:func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided
element *n* times, or returns the element endlessly if *n* is not provided. :: | itertools.cycle([1, 2, 3, 4, 5]) => 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
:func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided
element *n* times, or returns the element endlessly if *n* is not provided. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
87ffd637-a4b6-47be-9cad-4e57096e0701 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,087 | supabase-export-v2 | 4b59afc6a49bdc55 | as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
(:pep:`342` explains the exact rules, which are that a ``yield``-expression must
always be parenthesized except when it occurs at the top-level expression on the
right-... | trusted_official_docs | CPython Docs | as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
(:pep:`342` explains the exact rules, which are that a ``yield``-expression must
always be parenthesized except when it occurs at the top-level expression on the
right-... | as in the above example. The parentheses aren't always necessary, but it's easier to always add them instead of having to remember when they're needed.
(:pep:`342` explains the exact rules, which are that a ``yield``-expression must
always be parenthesized except when it occurs at the top-level expression on the
right-... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
884f22c9-e6c5-4ab3-8b4c-7821eb26d74c | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,070 | supabase-export-v2 | be1c6af19a27b584 | >>> def generate_ints(N): ... for i in range(N): ... yield i
Any function containing a :keyword:`yield` keyword is a generator function;
this is detected by Python's :term:`bytecode` compiler which compiles the
function specially as a result. | trusted_official_docs | CPython Docs | >>> def generate_ints(N): ... for i in range(N): ... yield i
Any function containing a :keyword:`yield` keyword is a generator function;
this is detected by Python's :term:`bytecode` compiler which compiles the
function specially as a result. | >>> def generate_ints(N): ... for i in range(N): ... yield i
Any function containing a :keyword:`yield` keyword is a generator function;
this is detected by Python's :term:`bytecode` compiler which compiles the
function specially as a result. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89c1f491-f298-42d9-845c-a4b4dc30d813 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,057 | supabase-export-v2 | 866d1d50b6a77f1c | obj_total = sum(obj.count for obj in list_all_objects())
The ``for...in`` clauses contain the sequences to be iterated over. The
sequences do not have to be the same length, because they are iterated over from
left to right, **not** in parallel. For each element in ``sequence1``,
``sequence2`` is looped over from the b... | trusted_official_docs | CPython Docs | obj_total = sum(obj.count for obj in list_all_objects())
The ``for...in`` clauses contain the sequences to be iterated over. The
sequences do not have to be the same length, because they are iterated over from
left to right, **not** in parallel. For each element in ``sequence1``,
``sequence2`` is looped over from the b... | obj_total = sum(obj.count for obj in list_all_objects())
The ``for...in`` clauses contain the sequences to be iterated over. The
sequences do not have to be the same length, because they are iterated over from
left to right, **not** in parallel. For each element in ``sequence1``,
``sequence2`` is looped over from the b... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89cdea53-5d29-479e-a0d6-b08234e7657e | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,997 | supabase-export-v2 | b76bf942774516cf | In Python you might combine the two approaches by writing functions that take and return instances representing objects in your application (e-mail messages, transactions, etc.).
Functional design may seem like an odd constraint to work under. Why should you
avoid objects and side effects? There are theoretical and pra... | trusted_official_docs | CPython Docs | In Python you might combine the two approaches by writing functions that take and return instances representing objects in your application (e-mail messages, transactions, etc.).
Functional design may seem like an odd constraint to work under. Why should you
avoid objects and side effects? There are theoretical and pra... | In Python you might combine the two approaches by writing functions that take and return instances representing objects in your application (e-mail messages, transactions, etc.).
Functional design may seem like an odd constraint to work under. Why should you
avoid objects and side effects? There are theoretical and pra... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89de7f6c-b9be-44bd-92bf-4ac92ec56d3d | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,052 | supabase-export-v2 | 7ac8f90522c9e907 | Generator expressions are surrounded by parentheses ("()") and list comprehensions are surrounded by square brackets ("[]"). Generator expressions have the form::
( expression for expr in sequence1
if condition1
for expr2 in sequence2
if condition2
for expr3 in sequence3
if condition3
... for exprN in sequenceN
... | trusted_official_docs | CPython Docs | Generator expressions are surrounded by parentheses ("()") and list comprehensions are surrounded by square brackets ("[]"). Generator expressions have the form::
( expression for expr in sequence1
if condition1
for expr2 in sequence2
if condition2
for expr3 in sequence3
if condition3
... for exprN in sequenceN
... | Generator expressions are surrounded by parentheses ("()") and list comprehensions are surrounded by square brackets ("[]"). Generator expressions have the form::
( expression for expr in sequence1
if condition1
for expr2 in sequence2
if condition2
for expr3 in sequence3
if condition3
... for exprN in sequenceN
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a04c82d-f0fb-421c-ad92-16e4c1c60f18 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,084 | supabase-export-v2 | 4d111ba1f51eac04 | by making the generator look at a global variable or by passing in some mutable object that callers then modify, but these approaches are messy.
In Python 2.5 there's a simple way to pass values into a generator. :keyword:`yield` became an expression, returning a value that can be assigned to
a variable or otherwise op... | trusted_official_docs | CPython Docs | by making the generator look at a global variable or by passing in some mutable object that callers then modify, but these approaches are messy.
In Python 2.5 there's a simple way to pass values into a generator. :keyword:`yield` became an expression, returning a value that can be assigned to
a variable or otherwise op... | by making the generator look at a global variable or by passing in some mutable object that callers then modify, but these approaches are messy.
In Python 2.5 there's a simple way to pass values into a generator. :keyword:`yield` became an expression, returning a value that can be assigned to
a variable or otherwise op... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a5cb8dd-1b27-462b-be5a-67928a1d1ccf | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,017 | supabase-export-v2 | c18a57ba59455142 | I'll start by looking at a Python language feature that's an important foundation for writing functional-style programs: iterators.
An iterator is an object representing a stream of data; this object returns the
data one element at a time. A Python iterator must support a method called
:meth:`~iterator.__next__` that t... | trusted_official_docs | CPython Docs | I'll start by looking at a Python language feature that's an important foundation for writing functional-style programs: iterators.
An iterator is an object representing a stream of data; this object returns the
data one element at a time. A Python iterator must support a method called
:meth:`~iterator.__next__` that t... | I'll start by looking at a Python language feature that's an important foundation for writing functional-style programs: iterators.
An iterator is an object representing a stream of data; this object returns the
data one element at a time. A Python iterator must support a method called
:meth:`~iterator.__next__` that t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8d511e8b-2f95-4d3d-ba55-fa47c0f54315 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,019 | supabase-export-v2 | fc95b8a48e0402bf | built-in data types support iteration, the most common being lists and dictionaries. An object is called :term:`iterable` if you can get an iterator for it.
You can experiment with the iteration interface manually: | trusted_official_docs | CPython Docs | built-in data types support iteration, the most common being lists and dictionaries. An object is called :term:`iterable` if you can get an iterator for it.
You can experiment with the iteration interface manually: | built-in data types support iteration, the most common being lists and dictionaries. An object is called :term:`iterable` if you can get an iterator for it.
You can experiment with the iteration interface manually: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8f322103-f7de-47e2-bb0f-562da6e4992b | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,196 | supabase-export-v2 | c19e77193066644b | recent call last): ... TypeError: reduce() of empty sequence with no initial value >>> functools.reduce(operator.mul, [1, 2, 3], 1) 6 >>> functools.reduce(operator.mul, [], 1) 1
If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all the
elements of the iterable. This case is so common that the... | trusted_official_docs | CPython Docs | recent call last): ... TypeError: reduce() of empty sequence with no initial value >>> functools.reduce(operator.mul, [1, 2, 3], 1) 6 >>> functools.reduce(operator.mul, [], 1) 1
If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all the
elements of the iterable. This case is so common that the... | recent call last): ... TypeError: reduce() of empty sequence with no initial value >>> functools.reduce(operator.mul, [1, 2, 3], 1) 6 >>> functools.reduce(operator.mul, [], 1) 1
If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all the
elements of the iterable. This case is so common that the... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8f85724b-0e44-4df4-9a6a-7e5517e239b8 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,211 | supabase-export-v2 | 24be991e6906a120 | When writing functional-style programs, you'll often need little functions that act as predicates or that combine elements in some way.
If there's a Python built-in or a module function that's suitable, you don't
need to define a new function at all:: | trusted_official_docs | CPython Docs | When writing functional-style programs, you'll often need little functions that act as predicates or that combine elements in some way.
If there's a Python built-in or a module function that's suitable, you don't
need to define a new function at all:: | When writing functional-style programs, you'll often need little functions that act as predicates or that combine elements in some way.
If there's a Python built-in or a module function that's suitable, you don't
need to define a new function at all:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9133e675-5aa2-4b9a-8c89-5ca4b62a36d0 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 56,998 | supabase-export-v2 | af816f068da8e2bf | like an odd constraint to work under. Why should you avoid objects and side effects? There are theoretical and practical advantages to the functional style:
* Formal provability. * Modularity. * Composability. * Ease of debugging and testing. | trusted_official_docs | CPython Docs | like an odd constraint to work under. Why should you avoid objects and side effects? There are theoretical and practical advantages to the functional style:
* Formal provability. * Modularity. * Composability. * Ease of debugging and testing. | like an odd constraint to work under. Why should you avoid objects and side effects? There are theoretical and practical advantages to the functional style:
* Formal provability. * Modularity. * Composability. * Ease of debugging and testing. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
91b22cad-14ed-4f2c-be2f-05034f4fa092 | CPython Docs | file://datasets/cpython/Doc/howto/functional.rst | unknown | 96a5a3c7-7880-46e2-a48a-2e8064e3ea09 | 57,179 | supabase-export-v2 | 6da2290cff8dde66 | compute a key value for each element returned by the iterable. If you don't supply a key function, the key is simply each element itself.
:func:`~itertools.groupby` collects all the consecutive elements from the
underlying iterable that have the same key value, and returns a stream of
2-tuples containing a key value an... | trusted_official_docs | CPython Docs | compute a key value for each element returned by the iterable. If you don't supply a key function, the key is simply each element itself.
:func:`~itertools.groupby` collects all the consecutive elements from the
underlying iterable that have the same key value, and returns a stream of
2-tuples containing a key value an... | compute a key value for each element returned by the iterable. If you don't supply a key function, the key is simply each element itself.
:func:`~itertools.groupby` collects all the consecutive elements from the
underlying iterable that have the same key value, and returns a stream of
2-tuples containing a key value an... | 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.