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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7166336b-e89a-451f-8a06-6c767c9039f5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,156 | supabase-export-v2 | a49069a4a606c9b4 | stop = len(iterable) if stop is None else stop i = start with suppress(ValueError): while True: yield (i := seq_index(value, i, stop)) i += 1
def iter_except(function, exception, first=None):
"Convert a call-until-exception interface to an iterator interface."
# iter_except(d.popitem, KeyError) → non-blocking diction... | trusted_official_docs | CPython Docs | stop = len(iterable) if stop is None else stop i = start with suppress(ValueError): while True: yield (i := seq_index(value, i, stop)) i += 1
def iter_except(function, exception, first=None):
"Convert a call-until-exception interface to an iterator interface."
# iter_except(d.popitem, KeyError) → non-blocking diction... | stop = len(iterable) if stop is None else stop i = start with suppress(ValueError): while True: yield (i := seq_index(value, i, stop)) i += 1
def iter_except(function, exception, first=None):
"Convert a call-until-exception interface to an iterator interface."
# iter_except(d.popitem, KeyError) → non-blocking diction... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
73c0572a-b046-46c0-92b4-8ad3b8443b50 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,029 | supabase-export-v2 | dcdf6612adff6d75 | *iterable* returning only those for which the *predicate* returns a false value. If *predicate* is ``None``, returns the items that are false. Roughly equivalent to::
def filterfalse(predicate, iterable):
# filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8 | trusted_official_docs | CPython Docs | *iterable* returning only those for which the *predicate* returns a false value. If *predicate* is ``None``, returns the items that are false. Roughly equivalent to::
def filterfalse(predicate, iterable):
# filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8 | *iterable* returning only those for which the *predicate* returns a false value. If *predicate* is ``None``, returns the items that are false. Roughly equivalent to::
def filterfalse(predicate, iterable):
# filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
74405a54-9413-4bf7-92c1-b974f54ae50c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,223 | supabase-export-v2 | ff06edc079b4aa32 | 0, 0] >>> random.seed(85753098575309) >>> list(repeatfunc(random.random, 3)) [0.16370491282496968, 0.45889608687313455, 0.3747076837820118] >>> list(repeatfunc(chr, 3, 65)) ['A', 'A', 'A'] >>> list(repeatfunc(pow, 3, 2, 5)) [32, 32, 32]
>>> list(grouper('abcdefg', 3, fillvalue='x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ... | trusted_official_docs | CPython Docs | 0, 0] >>> random.seed(85753098575309) >>> list(repeatfunc(random.random, 3)) [0.16370491282496968, 0.45889608687313455, 0.3747076837820118] >>> list(repeatfunc(chr, 3, 65)) ['A', 'A', 'A'] >>> list(repeatfunc(pow, 3, 2, 5)) [32, 32, 32]
>>> list(grouper('abcdefg', 3, fillvalue='x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ... | 0, 0] >>> random.seed(85753098575309) >>> list(repeatfunc(random.random, 3)) [0.16370491282496968, 0.45889608687313455, 0.3747076837820118] >>> list(repeatfunc(chr, 3, 65)) ['A', 'A', 'A'] >>> list(repeatfunc(pow, 3, 2, 5)) [32, 32, 32]
>>> list(grouper('abcdefg', 3, fillvalue='x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
74682a1d-dbb7-4f8e-933a-af2a3ba7f368 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,080 | supabase-export-v2 | 66730e69ef898d2b | if repeat < 0: raise ValueError('repeat argument cannot be negative') pools = [tuple(pool) for pool in iterables] * repeat
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool] | trusted_official_docs | CPython Docs | if repeat < 0: raise ValueError('repeat argument cannot be negative') pools = [tuple(pool) for pool in iterables] * repeat
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool] | if repeat < 0: raise ValueError('repeat argument cannot be negative') pools = [tuple(pool) for pool in iterables] * repeat
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
76109ef0-3b4d-460c-85ba-1d239f784e04 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,155 | supabase-export-v2 | 3fed10ab0a34dca6 | credited to Stefan Pochmann seq = tuple(iterable) pos = tuple(range(len(seq))) have_moved = map(map, repeat(is_not), repeat(pos), permutations(pos, r=r)) valid_derangements = map(all, have_moved) return compress(permutations(seq, r=r), valid_derangements)
def iter_index(iterable, value, start=0, stop=None):
"Return in... | trusted_official_docs | CPython Docs | credited to Stefan Pochmann seq = tuple(iterable) pos = tuple(range(len(seq))) have_moved = map(map, repeat(is_not), repeat(pos), permutations(pos, r=r)) valid_derangements = map(all, have_moved) return compress(permutations(seq, r=r), valid_derangements)
def iter_index(iterable, value, start=0, stop=None):
"Return in... | credited to Stefan Pochmann seq = tuple(iterable) pos = tuple(range(len(seq))) have_moved = map(map, repeat(is_not), repeat(pos), permutations(pos, r=r)) valid_derangements = map(all, have_moved) return compress(permutations(seq, r=r), valid_derangements)
def iter_index(iterable, value, start=0, stop=None):
"Return in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
765c34de-d425-4861-a962-edf844999dc7 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,045 | supabase-export-v2 | b39d62d81d6f9b71 | Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for *start*, *stop*, or *step*.
If *start* is zero or ``None``, iteration starts at zero. Otherwise,
elements from the iterable are skipped until *start* is reached. | trusted_official_docs | CPython Docs | Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for *start*, *stop*, or *step*.
If *start* is zero or ``None``, iteration starts at zero. Otherwise,
elements from the iterable are skipped until *start* is reached. | Make an iterator that returns selected elements from the iterable. Works like sequence slicing but does not support negative values for *start*, *stop*, or *step*.
If *start* is zero or ``None``, iteration starts at zero. Otherwise,
elements from the iterable are skipped until *start* is reached. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77406d64-1b27-420c-a79b-3e64b7f24a26 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,206 | supabase-export-v2 | 80f8213bbcb00e9e | >>> sum_of_squares([10, 20, 30]) 1400
>>> list(reshape([(0, 1), (2, 3), (4, 5)], 3))
[(0, 1, 2), (3, 4, 5)]
>>> M = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
>>> list(reshape(M, 1))
[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (11,)]
>>> list(reshape(M, 2))
[(0, 1), (2, 3), (4, 5), (6, 7... | trusted_official_docs | CPython Docs | >>> sum_of_squares([10, 20, 30]) 1400
>>> list(reshape([(0, 1), (2, 3), (4, 5)], 3))
[(0, 1, 2), (3, 4, 5)]
>>> M = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
>>> list(reshape(M, 1))
[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (11,)]
>>> list(reshape(M, 2))
[(0, 1), (2, 3), (4, 5), (6, 7... | >>> sum_of_squares([10, 20, 30]) 1400
>>> list(reshape([(0, 1), (2, 3), (4, 5)], 3))
[(0, 1, 2), (3, 4, 5)]
>>> M = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
>>> list(reshape(M, 1))
[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (11,)]
>>> list(reshape(M, 2))
[(0, 1), (2, 3), (4, 5), (6, 7... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77e6a4ef-11ba-4fb6-915a-6616237a3a9b | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,192 | supabase-export-v2 | d59b7e46ee7791b8 | = sorted(sorted(d.items()), key=itemgetter(1)) >>> for k, g in groupby(di, itemgetter(1)): ... print(k, list(map(itemgetter(0), g))) ... 1 ['a', 'c', 'e'] 2 ['b', 'd', 'f'] 3 ['g']
# Find runs of consecutive numbers using groupby. The key to the solution
# is differencing with a range so that consecutive numbers all a... | trusted_official_docs | CPython Docs | = sorted(sorted(d.items()), key=itemgetter(1)) >>> for k, g in groupby(di, itemgetter(1)): ... print(k, list(map(itemgetter(0), g))) ... 1 ['a', 'c', 'e'] 2 ['b', 'd', 'f'] 3 ['g']
# Find runs of consecutive numbers using groupby. The key to the solution
# is differencing with a range so that consecutive numbers all a... | = sorted(sorted(d.items()), key=itemgetter(1)) >>> for k, g in groupby(di, itemgetter(1)): ... print(k, list(map(itemgetter(0), g))) ... 1 ['a', 'c', 'e'] 2 ['b', 'd', 'f'] 3 ['g']
# Find runs of consecutive numbers using groupby. The key to the solution
# is differencing with a range so that consecutive numbers all a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77ee9005-324e-4041-ab79-69c266232df5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,047 | supabase-export-v2 | 3fcb09fa79c6f62c | If *stop* is ``None``, iteration continues until the input is exhausted, if at all. Otherwise, it stops at the specified position.
If *step* is ``None``, the step defaults to one. Elements are returned
consecutively unless *step* is set higher than one which results in
items being skipped. | trusted_official_docs | CPython Docs | If *stop* is ``None``, iteration continues until the input is exhausted, if at all. Otherwise, it stops at the specified position.
If *step* is ``None``, the step defaults to one. Elements are returned
consecutively unless *step* is set higher than one which results in
items being skipped. | If *stop* is ``None``, iteration continues until the input is exhausted, if at all. Otherwise, it stops at the specified position.
If *step* is ``None``, the step defaults to one. Elements are returned
consecutively unless *step* is set higher than one which results in
items being skipped. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
78c681e4-2f80-4ad0-b327-27171b17f0e2 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,230 | supabase-export-v2 | fbc1682198027671 | >>> list(subslices('ABCD')) ['A', 'AB', 'ABC', 'ABCD', 'B', 'BC', 'BCD', 'C', 'CD', 'D']
>>> ' '.join(map(''.join, derangements('ABCD')))
'BADC BCDA BDAC CADB CDAB CDBA DABC DCAB DCBA'
>>> ' '.join(map(''.join, derangements('ABCD', 3)))
'BAD BCA BCD BDA CAB CAD CDA CDB DAB DCA DCB'
>>> ' '.join(map(''.join, derange... | trusted_official_docs | CPython Docs | >>> list(subslices('ABCD')) ['A', 'AB', 'ABC', 'ABCD', 'B', 'BC', 'BCD', 'C', 'CD', 'D']
>>> ' '.join(map(''.join, derangements('ABCD')))
'BADC BCDA BDAC CADB CDAB CDBA DABC DCAB DCBA'
>>> ' '.join(map(''.join, derangements('ABCD', 3)))
'BAD BCA BCD BDA CAB CAD CDA CDB DAB DCA DCB'
>>> ' '.join(map(''.join, derange... | >>> list(subslices('ABCD')) ['A', 'AB', 'ABC', 'ABCD', 'B', 'BC', 'BCD', 'C', 'CD', 'D']
>>> ' '.join(map(''.join, derangements('ABCD')))
'BADC BCDA BDAC CADB CDAB CDBA DABC DCAB DCBA'
>>> ' '.join(map(''.join, derangements('ABCD', 3)))
'BAD BCA BCD BDA CAB CAD CDA CDB DAB DCA DCB'
>>> ' '.join(map(''.join, derange... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
78c751b2-d66a-48f2-8cd4-b68d4e906c9e | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,069 | supabase-export-v2 | 5c48656dae9cf477 | # permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC # permutations(range(3)) → 012 021 102 120 201 210
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
if r > n:
return | trusted_official_docs | CPython Docs | # permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC # permutations(range(3)) → 012 021 102 120 201 210
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
if r > n:
return | # permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC # permutations(range(3)) → 012 021 102 120 201 210
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
if r > n:
return | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7ad6a35e-1381-4eb2-932a-d44cebb44784 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,222 | supabase-export-v2 | 5f98a117625ff296 | >>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')])) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>> list(repeatfunc(pow, 5, 2, 3))
[8, 8, 8, 8, 8]
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]
>>> random.seed(85753098575309)
>>> list(repeatfunc(random.random, 3))
[0.... | trusted_official_docs | CPython Docs | >>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')])) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>> list(repeatfunc(pow, 5, 2, 3))
[8, 8, 8, 8, 8]
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]
>>> random.seed(85753098575309)
>>> list(repeatfunc(random.random, 3))
[0.... | >>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')])) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>> list(repeatfunc(pow, 5, 2, 3))
[8, 8, 8, 8, 8]
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]
>>> random.seed(85753098575309)
>>> list(repeatfunc(random.random, 3))
[0.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7c648e80-bd90-4a2d-a90d-f3e24e7f88c8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,126 | supabase-export-v2 | 0619549d36aa34df | This section shows recipes for creating an extended toolset using the existing itertools as building blocks.
The primary purpose of the itertools recipes is educational. The recipes show
various ways of thinking about individual tools — for example, that
``chain.from_iterable`` is related to the concept of flattening. ... | trusted_official_docs | CPython Docs | This section shows recipes for creating an extended toolset using the existing itertools as building blocks.
The primary purpose of the itertools recipes is educational. The recipes show
various ways of thinking about individual tools — for example, that
``chain.from_iterable`` is related to the concept of flattening. ... | This section shows recipes for creating an extended toolset using the existing itertools as building blocks.
The primary purpose of the itertools recipes is educational. The recipes show
various ways of thinking about individual tools — for example, that
``chain.from_iterable`` is related to the concept of flattening. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7cf1724d-b8ff-4c65-aa7c-5d70dd7f8c69 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,198 | supabase-export-v2 | 6ea878caf5cb29d8 | >>> for _ in loops(5): ... print('hi') ... hi hi hi hi hi
>>> list(tail(3, 'ABCDEFG'))
['E', 'F', 'G']
>>> # Verify the input is consumed greedily
>>> input_iterator = iter('ABCDEFG')
>>> output_iterator = tail(3, input_iterator)
>>> list(input_iterator)
[] | trusted_official_docs | CPython Docs | >>> for _ in loops(5): ... print('hi') ... hi hi hi hi hi
>>> list(tail(3, 'ABCDEFG'))
['E', 'F', 'G']
>>> # Verify the input is consumed greedily
>>> input_iterator = iter('ABCDEFG')
>>> output_iterator = tail(3, input_iterator)
>>> list(input_iterator)
[] | >>> for _ in loops(5): ... print('hi') ... hi hi hi hi hi
>>> list(tail(3, 'ABCDEFG'))
['E', 'F', 'G']
>>> # Verify the input is consumed greedily
>>> input_iterator = iter('ABCDEFG')
>>> output_iterator = tail(3, input_iterator)
>>> list(input_iterator)
[] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7cf837e8-e602-419d-b7ed-0326fd6c33d3 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,017 | supabase-export-v2 | 5743443b9a3adff1 | from the *iterable* and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely. Roughly equivalent to::
def cycle(iterable):
# cycle('ABCD') → A B C D A B C D A B C D ... | trusted_official_docs | CPython Docs | from the *iterable* and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely. Roughly equivalent to::
def cycle(iterable):
# cycle('ABCD') → A B C D A B C D A B C D ... | from the *iterable* and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely. Roughly equivalent to::
def cycle(iterable):
# cycle('ABCD') → A B C D A B C D A B C D ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d11af1e-ab56-453c-bed2-6b654061ff63 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,148 | supabase-export-v2 | 84226a7fb0852c10 | C D A B # unique_justseen('ABBcCAD', str.casefold) → A B c A D if key is None: return map(itemgetter(0), groupby(iterable)) return map(next, map(itemgetter(1), groupby(iterable, key)))
def unique_everseen(iterable, key=None):
"Yield unique elements, preserving order. Remember all elements ever seen."
# unique_eversee... | trusted_official_docs | CPython Docs | C D A B # unique_justseen('ABBcCAD', str.casefold) → A B c A D if key is None: return map(itemgetter(0), groupby(iterable)) return map(next, map(itemgetter(1), groupby(iterable, key)))
def unique_everseen(iterable, key=None):
"Yield unique elements, preserving order. Remember all elements ever seen."
# unique_eversee... | C D A B # unique_justseen('ABBcCAD', str.casefold) → A B c A D if key is None: return map(itemgetter(0), groupby(iterable)) return map(next, map(itemgetter(1), groupby(iterable, key)))
def unique_everseen(iterable, key=None):
"Yield unique elements, preserving order. Remember all elements ever seen."
# unique_eversee... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7f6c46cc-68e2-4507-8300-7dad3af8bffc | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,154 | supabase-export-v2 | e30d518604fc037e | sequence." # subslices('ABCD') → A AB ABC ABCD B BC BCD C CD D slices = starmap(slice, combinations(range(len(seq) + 1), 2)) return map(getitem, repeat(seq), slices)
def derangements(iterable, r=None):
"Produce r length permutations without fixed points."
# derangements('ABCD') → BADC BCDA BDAC CADB CDAB CDBA DABC DC... | trusted_official_docs | CPython Docs | sequence." # subslices('ABCD') → A AB ABC ABCD B BC BCD C CD D slices = starmap(slice, combinations(range(len(seq) + 1), 2)) return map(getitem, repeat(seq), slices)
def derangements(iterable, r=None):
"Produce r length permutations without fixed points."
# derangements('ABCD') → BADC BCDA BDAC CADB CDAB CDBA DABC DC... | sequence." # subslices('ABCD') → A AB ABC ABCD B BC BCD C CD D slices = starmap(slice, combinations(range(len(seq) + 1), 2)) return map(getitem, repeat(seq), slices)
def derangements(iterable, r=None):
"Produce r length permutations without fixed points."
# derangements('ABCD') → BADC BCDA BDAC CADB CDAB CDBA DABC DC... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8051c978-e3a9-4443-90a6-95604ae3aaf2 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,147 | supabase-export-v2 | fe58848c323fc9c5 | # ==== Data pipelines ====
def unique_justseen(iterable, key=None):
"Yield unique elements, preserving order. Remember only the element just seen."
# unique_justseen('AAAABBBCCDAABBB') → A B C D A B
# unique_justseen('ABBcCAD', str.casefold) → A B c A D
if key is None:
return map(itemgetter(0), groupby(iterable))
... | trusted_official_docs | CPython Docs | # ==== Data pipelines ====
def unique_justseen(iterable, key=None):
"Yield unique elements, preserving order. Remember only the element just seen."
# unique_justseen('AAAABBBCCDAABBB') → A B C D A B
# unique_justseen('ABBcCAD', str.casefold) → A B c A D
if key is None:
return map(itemgetter(0), groupby(iterable))
... | # ==== Data pipelines ====
def unique_justseen(iterable, key=None):
"Yield unique elements, preserving order. Remember only the element just seen."
# unique_justseen('AAAABBBCCDAABBB') → A B C D A B
# unique_justseen('ABBcCAD', str.casefold) → A B c A D
if key is None:
return map(itemgetter(0), groupby(iterable))
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
815290ec-a95b-4e5e-aef1-0599a64a8dbc | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,185 | supabase-export-v2 | 0c1f3af4e6e5d38b | size as or one smaller than lo with suppress(StopIteration): while True: heappush_max(lo, heappushpop(hi, read())) yield lo[0] heappush(hi, heappushpop_max(lo, read())) yield (lo[0] + hi[0]) / 2
def running_statistics(iterable):
"Aggregate statistics for values seen so far."
# Generate tuples: (size, minimum, median,... | trusted_official_docs | CPython Docs | size as or one smaller than lo with suppress(StopIteration): while True: heappush_max(lo, heappushpop(hi, read())) yield lo[0] heappush(hi, heappushpop_max(lo, read())) yield (lo[0] + hi[0]) / 2
def running_statistics(iterable):
"Aggregate statistics for values seen so far."
# Generate tuples: (size, minimum, median,... | size as or one smaller than lo with suppress(StopIteration): while True: heappush_max(lo, heappushpop(hi, read())) yield lo[0] heappush(hi, heappushpop_max(lo, read())) yield (lo[0] + hi[0]) / 2
def running_statistics(iterable):
"Aggregate statistics for values seen so far."
# Generate tuples: (size, minimum, median,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8161c543-247d-41fb-8418-03983f6edca1 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,130 | supabase-export-v2 | e102696e0c4b2544 | python -m pip install more-itertools
Many of the recipes offer the same high performance as the underlying toolset. Superior memory performance is kept by processing elements one at a time rather
than bringing the whole iterable into memory all at once. Code volume is kept
small by linking the tools together in a `func... | trusted_official_docs | CPython Docs | python -m pip install more-itertools
Many of the recipes offer the same high performance as the underlying toolset. Superior memory performance is kept by processing elements one at a time rather
than bringing the whole iterable into memory all at once. Code volume is kept
small by linking the tools together in a `func... | python -m pip install more-itertools
Many of the recipes offer the same high performance as the underlying toolset. Superior memory performance is kept by processing elements one at a time rather
than bringing the whole iterable into memory all at once. Code volume is kept
small by linking the tools together in a `func... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
82740254-03e5-4195-81b0-a596bc0e6684 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,034 | supabase-export-v2 | 3e1c5a6a837568c9 | ``None``, *key* defaults to an identity function and returns the element unchanged. Generally, the iterable needs to already be sorted on the same key function.
The operation of :func:`groupby` is similar to the ``uniq`` filter in Unix. It
generates a break or new group every time the value of the key function changes... | trusted_official_docs | CPython Docs | ``None``, *key* defaults to an identity function and returns the element unchanged. Generally, the iterable needs to already be sorted on the same key function.
The operation of :func:`groupby` is similar to the ``uniq`` filter in Unix. It
generates a break or new group every time the value of the key function changes... | ``None``, *key* defaults to an identity function and returns the element unchanged. Generally, the iterable needs to already be sorted on the same key function.
The operation of :func:`groupby` is similar to the ``uniq`` filter in Unix. It
generates a break or new group every time the value of the key function changes... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
82b66e22-c842-4212-a8e5-0bb7a93b8bd3 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,232 | supabase-export-v2 | 8596f8f77c4f7c7d | (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)] >>> all(len(list(powerset(range(n)))) == 2**n for n in range(18)) True >>> list(powerset('abcde')) == sorted(sorted(set(powerset('abcde'))), key=len) True
>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']
>>> list(unique_everseen('ABBCcAD', str.casefold))
['A'... | trusted_official_docs | CPython Docs | (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)] >>> all(len(list(powerset(range(n)))) == 2**n for n in range(18)) True >>> list(powerset('abcde')) == sorted(sorted(set(powerset('abcde'))), key=len) True
>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']
>>> list(unique_everseen('ABBCcAD', str.casefold))
['A'... | (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)] >>> all(len(list(powerset(range(n)))) == 2**n for n in range(18)) True >>> list(powerset('abcde')) == sorted(sorted(set(powerset('abcde'))), key=len) True
>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']
>>> list(unique_everseen('ABBCcAD', str.casefold))
['A'... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8375fd2e-5c1c-48d9-ba41-cd0f815bbb93 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,983 | supabase-export-v2 | 5bf3bad307bc708a | then proceeds to the next iterable, until all of the iterables are exhausted. This combines multiple data sources into a single iterator. Roughly equivalent to::
def chain(*iterables):
# chain('ABC', 'DEF') → A B C D E F
for iterable in iterables:
yield from iterable | trusted_official_docs | CPython Docs | then proceeds to the next iterable, until all of the iterables are exhausted. This combines multiple data sources into a single iterator. Roughly equivalent to::
def chain(*iterables):
# chain('ABC', 'DEF') → A B C D E F
for iterable in iterables:
yield from iterable | then proceeds to the next iterable, until all of the iterables are exhausted. This combines multiple data sources into a single iterator. Roughly equivalent to::
def chain(*iterables):
# chain('ABC', 'DEF') → A B C D E F
for iterable in iterables:
yield from iterable | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84eb4388-8b91-402a-8916-61b770881d29 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,145 | supabase-export-v2 | c1910b47033cdf57 | or b or c or x # first_true([a, b], x, f) → a if f(a) else b if f(b) else x return next(filter(predicate, iterable), default)
def all_equal(iterable, key=None):
"Returns True if all the elements are equal to each other."
# all_equal('4٤௪౪໔', key=int) → True
return len(take(2, groupby(iterable, key))) <= 1 | trusted_official_docs | CPython Docs | or b or c or x # first_true([a, b], x, f) → a if f(a) else b if f(b) else x return next(filter(predicate, iterable), default)
def all_equal(iterable, key=None):
"Returns True if all the elements are equal to each other."
# all_equal('4٤௪౪໔', key=int) → True
return len(take(2, groupby(iterable, key))) <= 1 | or b or c or x # first_true([a, b], x, f) → a if f(a) else b if f(b) else x return next(filter(predicate, iterable), default)
def all_equal(iterable, key=None):
"Returns True if all the elements are equal to each other."
# all_equal('4٤௪౪໔', key=int) → True
return len(take(2, groupby(iterable, key))) <= 1 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
85d27000-4d98-4e66-9d2a-c9d1a7d29da4 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,160 | supabase-export-v2 | 8d01936c324e7819 | from shortest to longest." # powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
def sum_of_squares(iterable):
"Add up the squares of the input values."
# sum_of_squares([10, 20, 30]) → 1400
return sumprod(*tee(ite... | trusted_official_docs | CPython Docs | from shortest to longest." # powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
def sum_of_squares(iterable):
"Add up the squares of the input values."
# sum_of_squares([10, 20, 30]) → 1400
return sumprod(*tee(ite... | from shortest to longest." # powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
def sum_of_squares(iterable):
"Add up the squares of the input values."
# sum_of_squares([10, 20, 30]) → 1400
return sumprod(*tee(ite... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
86554118-2346-4d13-8d44-8fa9c152e5f6 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,046 | supabase-export-v2 | 9b877875ad3abb08 | If *start* is zero or ``None``, iteration starts at zero. Otherwise, elements from the iterable are skipped until *start* is reached.
If *stop* is ``None``, iteration continues until the input is
exhausted, if at all. Otherwise, it stops at the specified position. | trusted_official_docs | CPython Docs | If *start* is zero or ``None``, iteration starts at zero. Otherwise, elements from the iterable are skipped until *start* is reached.
If *stop* is ``None``, iteration continues until the input is
exhausted, if at all. Otherwise, it stops at the specified position. | If *start* is zero or ``None``, iteration starts at zero. Otherwise, elements from the iterable are skipped until *start* is reached.
If *stop* is ``None``, iteration continues until the input is
exhausted, if at all. Otherwise, it stops at the specified position. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
874d4e8b-27b6-44be-ba48-91f95350e1a0 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,990 | supabase-export-v2 | 1e0260abfecce2c4 | is given by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | trusted_official_docs | CPython Docs | is given by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | is given by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The combination tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8779b390-883f-4a54-952c-3271b2cada5e | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,151 | supabase-export-v2 | 1e110803aa549036 | sliding_window('ABCDEFG', 3) → ABC BCD CDE DEF EFG iterator = iter(iterable) window = deque(islice(iterator, n - 1), maxlen=n) for x in iterator: window.append(x) yield tuple(window)
def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
"Collect data into non-overlapping fixed-length chunks or blocks."
# gr... | trusted_official_docs | CPython Docs | sliding_window('ABCDEFG', 3) → ABC BCD CDE DEF EFG iterator = iter(iterable) window = deque(islice(iterator, n - 1), maxlen=n) for x in iterator: window.append(x) yield tuple(window)
def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
"Collect data into non-overlapping fixed-length chunks or blocks."
# gr... | sliding_window('ABCDEFG', 3) → ABC BCD CDE DEF EFG iterator = iter(iterable) window = deque(islice(iterator, n - 1), maxlen=n) for x in iterator: window.append(x) yield tuple(window)
def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
"Collect data into non-overlapping fixed-length chunks or blocks."
# gr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a1d29ed-1d6a-482f-8442-caac50c8fac8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,008 | supabase-export-v2 | f21d876f3caf788c | elements from *data* where the corresponding element in *selectors* is true. Stops when either the *data* or *selectors* iterables have been exhausted. Roughly equivalent to::
def compress(data, selectors):
# compress('ABCDEF', [1,0,1,0,1,1]) → A C E F
return (datum for datum, selector in zip(data, selectors) if sele... | trusted_official_docs | CPython Docs | elements from *data* where the corresponding element in *selectors* is true. Stops when either the *data* or *selectors* iterables have been exhausted. Roughly equivalent to::
def compress(data, selectors):
# compress('ABCDEF', [1,0,1,0,1,1]) → A C E F
return (datum for datum, selector in zip(data, selectors) if sele... | elements from *data* where the corresponding element in *selectors* is true. Stops when either the *data* or *selectors* iterables have been exhausted. Roughly equivalent to::
def compress(data, selectors):
# compress('ABCDEF', [1,0,1,0,1,1]) → A C E F
return (datum for datum, selector in zip(data, selectors) if sele... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a8101de-08c1-434a-a25b-689b096cdca5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,091 | supabase-export-v2 | 7284126d6b68faa2 | .. function:: starmap(function, iterable)
Make an iterator that computes the *function* using arguments obtained
from the *iterable*. Used instead of :func:`map` when argument
parameters have already been "pre-zipped" into tuples. | trusted_official_docs | CPython Docs | .. function:: starmap(function, iterable)
Make an iterator that computes the *function* using arguments obtained
from the *iterable*. Used instead of :func:`map` when argument
parameters have already been "pre-zipped" into tuples. | .. function:: starmap(function, iterable)
Make an iterator that computes the *function* using arguments obtained
from the *iterable*. Used instead of :func:`map` when argument
parameters have already been "pre-zipped" into tuples. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8e6b8aa0-226f-41d2-af76-392d8772bed7 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,135 | supabase-export-v2 | 3084c4f58dc3cbc0 | def take(n, iterable): "Return first n items of the iterable as a list." return list(islice(iterable, n))
def prepend(value, iterable):
"Prepend a single value in front of an iterable."
# prepend(1, [2, 3, 4]) → 1 2 3 4
return chain([value], iterable) | trusted_official_docs | CPython Docs | def take(n, iterable): "Return first n items of the iterable as a list." return list(islice(iterable, n))
def prepend(value, iterable):
"Prepend a single value in front of an iterable."
# prepend(1, [2, 3, 4]) → 1 2 3 4
return chain([value], iterable) | def take(n, iterable): "Return first n items of the iterable as a list." return list(islice(iterable, n))
def prepend(value, iterable):
"Prepend a single value in front of an iterable."
# prepend(1, [2, 3, 4]) → 1 2 3 4
return chain([value], iterable) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8ea3286a-f621-4223-bc09-1153e68c27b2 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,174 | supabase-export-v2 | 364211456c1fa17d | def polynomial_derivative(coefficients): """Compute the first derivative of a polynomial.
f(x) = x³ -4x² -17x + 60
f'(x) = 3x² -8x -17
"""
# polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17]
n = len(coefficients)
powers = reversed(range(1, n))
return list(map(mul, coefficients, powers)) | trusted_official_docs | CPython Docs | def polynomial_derivative(coefficients): """Compute the first derivative of a polynomial.
f(x) = x³ -4x² -17x + 60
f'(x) = 3x² -8x -17
"""
# polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17]
n = len(coefficients)
powers = reversed(range(1, n))
return list(map(mul, coefficients, powers)) | def polynomial_derivative(coefficients): """Compute the first derivative of a polynomial.
f(x) = x³ -4x² -17x + 60
f'(x) = 3x² -8x -17
"""
# polynomial_derivative([1, -4, -17, 60]) → [3, -8, -17]
n = len(coefficients)
powers = reversed(range(1, n))
return list(map(mul, coefficients, powers)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8eec9345-6340-4bcb-94da-6024782d2c75 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,012 | supabase-export-v2 | 7e18c9fe12affebc | spaced values beginning with *start*. Can be used with :func:`map` to generate consecutive data points or with :func:`zip` to add sequence numbers. Roughly equivalent to::
def count(start=0, step=1):
# count(10) → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start
while True:
yield n
n += step | trusted_official_docs | CPython Docs | spaced values beginning with *start*. Can be used with :func:`map` to generate consecutive data points or with :func:`zip` to add sequence numbers. Roughly equivalent to::
def count(start=0, step=1):
# count(10) → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start
while True:
yield n
n += step | spaced values beginning with *start*. Can be used with :func:`map` to generate consecutive data points or with :func:`zip` to add sequence numbers. Roughly equivalent to::
def count(start=0, step=1):
# count(10) → 10 11 12 13 14 ... # count(2.5, 0.5) → 2.5 3.0 3.5 ... n = start
while True:
yield n
n += step | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
929c7c67-103e-4afa-8b7b-6a076bda3025 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,087 | supabase-export-v2 | c03c4c05e0661549 | def repeat(object, times=None): # repeat(10, 3) → 10 10 10 if times is None: while True: yield object else: for i in range(times): yield object
A common use for *repeat* is to supply a stream of constant values to *map*
or *zip*: | trusted_official_docs | CPython Docs | def repeat(object, times=None): # repeat(10, 3) → 10 10 10 if times is None: while True: yield object else: for i in range(times): yield object
A common use for *repeat* is to supply a stream of constant values to *map*
or *zip*: | def repeat(object, times=None): # repeat(10, 3) → 10 10 10 if times is None: while True: yield object else: for i in range(times): yield object
A common use for *repeat* is to supply a stream of constant values to *map*
or *zip*: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93d05d05-b1fc-4b5a-af55-65fe8bec6e29 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,144 | supabase-export-v2 | 613f70338e87afaa | def quantify(iterable, predicate=bool): "Given a predicate that returns True or False, count the True results." return sum(map(predicate, iterable))
def first_true(iterable, default=False, predicate=None):
"Returns the first true value or the *default* if there is no true value."
# first_true([a, b, c], x) → a or b o... | trusted_official_docs | CPython Docs | def quantify(iterable, predicate=bool): "Given a predicate that returns True or False, count the True results." return sum(map(predicate, iterable))
def first_true(iterable, default=False, predicate=None):
"Returns the first true value or the *default* if there is no true value."
# first_true([a, b, c], x) → a or b o... | def quantify(iterable, predicate=bool): "Given a predicate that returns True or False, count the True results." return sum(map(predicate, iterable))
def first_true(iterable, default=False, predicate=None):
"Returns the first true value or the *default* if there is no true value."
# first_true([a, b, c], x) → a or b o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94e72ea0-60ae-4038-b097-cb2930f9eb50 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,253 | supabase-export-v2 | 5727a935f25bbab0 | def before_and_after(predicate, it): """ Variant of takewhile() that allows complete access to the remainder of the iterator.
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI' | trusted_official_docs | CPython Docs | def before_and_after(predicate, it): """ Variant of takewhile() that allows complete access to the remainder of the iterator.
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI' | def before_and_after(predicate, it): """ Variant of takewhile() that allows complete access to the remainder of the iterator.
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
96220082-a13c-4736-be38-95e00d394561 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,203 | supabase-export-v2 | 63ef48a97493cbd6 | >>> quantify(range(99), lambda x: x%2==0) 50 >>> quantify([True, False, False, True, True]) 3 >>> quantify(range(12), predicate=lambda x: x%2==1) 6
>>> a = [[1, 2, 3], [4, 5, 6]]
>>> list(flatten(a))
[1, 2, 3, 4, 5, 6] | trusted_official_docs | CPython Docs | >>> quantify(range(99), lambda x: x%2==0) 50 >>> quantify([True, False, False, True, True]) 3 >>> quantify(range(12), predicate=lambda x: x%2==1) 6
>>> a = [[1, 2, 3], [4, 5, 6]]
>>> list(flatten(a))
[1, 2, 3, 4, 5, 6] | >>> quantify(range(99), lambda x: x%2==0) 50 >>> quantify([True, False, False, True, True]) 3 >>> quantify(range(12), predicate=lambda x: x%2==1) 6
>>> a = [[1, 2, 3], [4, 5, 6]]
>>> list(flatten(a))
[1, 2, 3, 4, 5, 6] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
97167d35-dfea-4412-bd91-b40e109a2eb0 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,076 | supabase-export-v2 | f669d352f733c7fe | on every iteration. This pattern creates a lexicographic ordering so that if the input's iterables are sorted, the product tuples are emitted in sorted order.
To compute the product of an iterable with itself, specify the number of
repetitions with the optional *repeat* keyword argument. For example,
``product(A, rep... | trusted_official_docs | CPython Docs | on every iteration. This pattern creates a lexicographic ordering so that if the input's iterables are sorted, the product tuples are emitted in sorted order.
To compute the product of an iterable with itself, specify the number of
repetitions with the optional *repeat* keyword argument. For example,
``product(A, rep... | on every iteration. This pattern creates a lexicographic ordering so that if the input's iterables are sorted, the product tuples are emitted in sorted order.
To compute the product of an iterable with itself, specify the number of
repetitions with the optional *repeat* keyword argument. For example,
``product(A, rep... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9993a298-06db-4b33-8302-462847aa1b20 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,116 | supabase-export-v2 | ad1b35a1218a0963 | Make an iterator that aggregates elements from each of the *iterables*.
If the iterables are of uneven length, missing values are filled-in
with *fillvalue*. If not specified, *fillvalue* defaults to ``None``. | trusted_official_docs | CPython Docs | Make an iterator that aggregates elements from each of the *iterables*.
If the iterables are of uneven length, missing values are filled-in
with *fillvalue*. If not specified, *fillvalue* defaults to ``None``. | Make an iterator that aggregates elements from each of the *iterables*.
If the iterables are of uneven length, missing values are filled-in
with *fillvalue*. If not specified, *fillvalue* defaults to ``None``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9a00fef8-0372-4c10-a996-79b447f0b1b4 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,209 | supabase-export-v2 | 355491acbc549467 | [[7, 11, 5, 4, 9], [3, 5, 2, 6, 3]])) [(29, 47, 20, 38, 33), (76, 122, 53, 82, 90), (33, 53, 23, 36, 39)]
>>> list(convolve([1, -1, -20], [1, -3])) == [1, -4, -17, 60]
True
>>> data = [20, 40, 24, 32, 20, 28, 16]
>>> list(convolve(data, [0.25, 0.25, 0.25, 0.25]))
[5.0, 15.0, 21.0, 29.0, 29.0, 26.0, 24.0, 16.0, 11.0... | trusted_official_docs | CPython Docs | [[7, 11, 5, 4, 9], [3, 5, 2, 6, 3]])) [(29, 47, 20, 38, 33), (76, 122, 53, 82, 90), (33, 53, 23, 36, 39)]
>>> list(convolve([1, -1, -20], [1, -3])) == [1, -4, -17, 60]
True
>>> data = [20, 40, 24, 32, 20, 28, 16]
>>> list(convolve(data, [0.25, 0.25, 0.25, 0.25]))
[5.0, 15.0, 21.0, 29.0, 29.0, 26.0, 24.0, 16.0, 11.0... | [[7, 11, 5, 4, 9], [3, 5, 2, 6, 3]])) [(29, 47, 20, 38, 33), (76, 122, 53, 82, 90), (33, 53, 23, 36, 39)]
>>> list(convolve([1, -1, -20], [1, -3])) == [1, -4, -17, 60]
True
>>> data = [20, 40, 24, 32, 20, 28, 16]
>>> list(convolve(data, [0.25, 0.25, 0.25, 0.25]))
[5.0, 15.0, 21.0, 29.0, 29.0, 26.0, 24.0, 16.0, 11.0... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9d038a47-a04f-4a8f-84cf-da67d65220b6 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,225 | supabase-export-v2 | c32de97336050627 | ('a', 'b', 'c') >>> next(it) ('d', 'e', 'f') >>> next(it) Traceback (most recent call last): ... ValueError: zip() argument 2 is shorter than argument 1
>>> list(grouper('abcdefg', n=3, incomplete='ignore'))
[('a', 'b', 'c'), ('d', 'e', 'f')] | trusted_official_docs | CPython Docs | ('a', 'b', 'c') >>> next(it) ('d', 'e', 'f') >>> next(it) Traceback (most recent call last): ... ValueError: zip() argument 2 is shorter than argument 1
>>> list(grouper('abcdefg', n=3, incomplete='ignore'))
[('a', 'b', 'c'), ('d', 'e', 'f')] | ('a', 'b', 'c') >>> next(it) ('d', 'e', 'f') >>> next(it) Traceback (most recent call last): ... ValueError: zip() argument 2 is shorter than argument 1
>>> list(grouper('abcdefg', n=3, incomplete='ignore'))
[('a', 'b', 'c'), ('d', 'e', 'f')] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9dabce81-ac65-47f1-9ba2-9ae45b85aae5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,963 | supabase-export-v2 | 1e6b3c38f91e73d9 | yield total for element in iterator: total = function(total, element) yield total
To compute a running minimum, set *function* to :func:`min`. For a running maximum, set *function* to :func:`max`. Or for a running product, set *function* to :func:`operator.mul`. To build an `amortization table
<https://www.ramseysolut... | trusted_official_docs | CPython Docs | yield total for element in iterator: total = function(total, element) yield total
To compute a running minimum, set *function* to :func:`min`. For a running maximum, set *function* to :func:`max`. Or for a running product, set *function* to :func:`operator.mul`. To build an `amortization table
<https://www.ramseysolut... | yield total for element in iterator: total = function(total, element) yield total
To compute a running minimum, set *function* to :func:`min`. For a running maximum, set *function* to :func:`max`. Or for a running product, set *function* to :func:`operator.mul`. To build an `amortization table
<https://www.ramseysolut... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e2ec017-1ec1-44e7-a2d1-974856ef6f20 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,219 | supabase-export-v2 | a52fb7ea4e0d05c8 | is_prime(128_884_753_939) # large prime True >>> is_prime(999953 * 999983) # large semiprime False >>> is_prime(1_000_000_000_000_007) # factor() example False >>> is_prime(1_000_000_000_000_403) # factor() example True
>>> list(factor(99)) # Code example 1
[3, 3, 11]
>>> list(factor(1_000_000_000_000_007)) # Code ex... | trusted_official_docs | CPython Docs | is_prime(128_884_753_939) # large prime True >>> is_prime(999953 * 999983) # large semiprime False >>> is_prime(1_000_000_000_000_007) # factor() example False >>> is_prime(1_000_000_000_000_403) # factor() example True
>>> list(factor(99)) # Code example 1
[3, 3, 11]
>>> list(factor(1_000_000_000_000_007)) # Code ex... | is_prime(128_884_753_939) # large prime True >>> is_prime(999953 * 999983) # large semiprime False >>> is_prime(1_000_000_000_000_007) # factor() example False >>> is_prime(1_000_000_000_000_403) # factor() example True
>>> list(factor(99)) # Code example 1
[3, 3, 11]
>>> list(factor(1_000_000_000_000_007)) # Code ex... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1470aaf-95a9-4fd5-9fe6-3fdb1609aa02 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,011 | supabase-export-v2 | f2a1232ed5a7b663 | .. function:: count(start=0, step=1)
Make an iterator that returns evenly spaced values beginning with
*start*. Can be used with :func:`map` to generate consecutive data
points or with :func:`zip` to add sequence numbers. Roughly
equivalent to:: | trusted_official_docs | CPython Docs | .. function:: count(start=0, step=1)
Make an iterator that returns evenly spaced values beginning with
*start*. Can be used with :func:`map` to generate consecutive data
points or with :func:`zip` to add sequence numbers. Roughly
equivalent to:: | .. function:: count(start=0, step=1)
Make an iterator that returns evenly spaced values beginning with
*start*. Can be used with :func:`map` to generate consecutive data
points or with :func:`zip` to add sequence numbers. Roughly
equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1a89ee6-0923-4e05-9572-8f5bc8574af8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,982 | supabase-export-v2 | 20ad7bab0a8e78a0 | .. function:: chain(*iterables)
Make an iterator that returns elements from the first iterable until
it is exhausted, then proceeds to the next iterable, until all of the
iterables are exhausted. This combines multiple data sources into a
single iterator. Roughly equivalent to:: | trusted_official_docs | CPython Docs | .. function:: chain(*iterables)
Make an iterator that returns elements from the first iterable until
it is exhausted, then proceeds to the next iterable, until all of the
iterables are exhausted. This combines multiple data sources into a
single iterator. Roughly equivalent to:: | .. function:: chain(*iterables)
Make an iterator that returns elements from the first iterable until
it is exhausted, then proceeds to the next iterable, until all of the
iterables are exhausted. This combines multiple data sources into a
single iterator. Roughly equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1af17af-8201-494c-8853-e63644bb088b | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,172 | supabase-export-v2 | 60b52d09afaad8ce | def polynomial_eval(coefficients, x): """Evaluate a polynomial at a specific value.
Computes with better numeric stability than Horner's method. """
# Evaluate x³ -4x² -17x + 60 at x = 5
# polynomial_eval([1, -4, -17, 60], x=5) → 0
n = len(coefficients)
if not n:
return type(x)(0)
powers = map(pow, repeat(x), rev... | trusted_official_docs | CPython Docs | def polynomial_eval(coefficients, x): """Evaluate a polynomial at a specific value.
Computes with better numeric stability than Horner's method. """
# Evaluate x³ -4x² -17x + 60 at x = 5
# polynomial_eval([1, -4, -17, 60], x=5) → 0
n = len(coefficients)
if not n:
return type(x)(0)
powers = map(pow, repeat(x), rev... | def polynomial_eval(coefficients, x): """Evaluate a polynomial at a specific value.
Computes with better numeric stability than Horner's method. """
# Evaluate x³ -4x² -17x + 60 at x = 5
# polynomial_eval([1, -4, -17, 60], x=5) → 0
n = len(coefficients)
if not n:
return type(x)(0)
powers = map(pow, repeat(x), rev... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a452736a-de3d-4168-bc3f-c0e12cc2c70d | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,171 | supabase-export-v2 | 15d721f5c7372b2d | to: x³ -4x² -17x + 60 """ # polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60] factors = zip(repeat(1), map(neg, roots)) return list(reduce(convolve, factors, [1]))
def polynomial_eval(coefficients, x):
"""Evaluate a polynomial at a specific value. | trusted_official_docs | CPython Docs | to: x³ -4x² -17x + 60 """ # polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60] factors = zip(repeat(1), map(neg, roots)) return list(reduce(convolve, factors, [1]))
def polynomial_eval(coefficients, x):
"""Evaluate a polynomial at a specific value. | to: x³ -4x² -17x + 60 """ # polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60] factors = zip(repeat(1), map(neg, roots)) return list(reduce(convolve, factors, [1]))
def polynomial_eval(coefficients, x):
"""Evaluate a polynomial at a specific value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a47c45ec-d550-4030-8744-9f91155090a4 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,947 | supabase-export-v2 | 7910e936ab5f769a | D E F G`` :func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') → AB BC CD DE EF FG`` :func:`repeat` elem [,n] elem, elem, elem, ...
endlessly or up to n times ``repeat(10, 3) → 10 10 10``
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 10... | trusted_official_docs | CPython Docs | D E F G`` :func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') → AB BC CD DE EF FG`` :func:`repeat` elem [,n] elem, elem, elem, ...
endlessly or up to n times ``repeat(10, 3) → 10 10 10``
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 10... | D E F G`` :func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') → AB BC CD DE EF FG`` :func:`repeat` elem [,n] elem, elem, elem, ...
endlessly or up to n times ``repeat(10, 3) → 10 10 10``
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 10... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8607040-01b9-4510-aad4-65016ce8159c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,136 | supabase-export-v2 | 5b812f64029bcdc2 | def prepend(value, iterable): "Prepend a single value in front of an iterable." # prepend(1, [2, 3, 4]) → 1 2 3 4 return chain([value], iterable)
def repeatfunc(function, times=None, *args):
"Repeat calls to a function with specified arguments."
if times is None:
return starmap(function, repeat(args))
return starma... | trusted_official_docs | CPython Docs | def prepend(value, iterable): "Prepend a single value in front of an iterable." # prepend(1, [2, 3, 4]) → 1 2 3 4 return chain([value], iterable)
def repeatfunc(function, times=None, *args):
"Repeat calls to a function with specified arguments."
if times is None:
return starmap(function, repeat(args))
return starma... | def prepend(value, iterable): "Prepend a single value in front of an iterable." # prepend(1, [2, 3, 4]) → 1 2 3 4 return chain([value], iterable)
def repeatfunc(function, times=None, *args):
"Repeat calls to a function with specified arguments."
if times is None:
return starmap(function, repeat(args))
return starma... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a861de2a-1999-4db9-a884-2aee1d8a9156 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,039 | supabase-export-v2 | cd937121757656c7 | [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D
keyfunc = (lambda x: x) if key is None else key
iterator = iter(iterable)
exhausted = False | trusted_official_docs | CPython Docs | [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D
keyfunc = (lambda x: x) if key is None else key
iterator = iter(iterable)
exhausted = False | [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D
keyfunc = (lambda x: x) if key is None else key
iterator = iter(iterable)
exhausted = False | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9b90270-0889-482d-b14c-7c35d03daacd | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,113 | supabase-export-v2 | 977e83b635e33d36 | are not threadsafe. A :exc:`RuntimeError` may be raised when simultaneously using iterators returned by the same :func:`tee` call, even if the original *iterable* is threadsafe.
This itertool may require significant auxiliary storage (depending on how
much temporary data needs to be stored). In general, if one iterato... | trusted_official_docs | CPython Docs | are not threadsafe. A :exc:`RuntimeError` may be raised when simultaneously using iterators returned by the same :func:`tee` call, even if the original *iterable* is threadsafe.
This itertool may require significant auxiliary storage (depending on how
much temporary data needs to be stored). In general, if one iterato... | are not threadsafe. A :exc:`RuntimeError` may be raised when simultaneously using iterators returned by the same :func:`tee` call, even if the original *iterable* is threadsafe.
This itertool may require significant auxiliary storage (depending on how
much temporary data needs to be stored). In general, if one iterato... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aab0dcb9-aa5c-48c7-bc73-8b10d477a188 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,163 | supabase-export-v2 | bf41aa082e234b02 | have a given number of columns." # reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5) return batched(chain.from_iterable(matrix), columns, strict=True)
def transpose(matrix):
"Swap the rows and columns of a 2-D matrix."
# transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33)
return zip(*matrix, stri... | trusted_official_docs | CPython Docs | have a given number of columns." # reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5) return batched(chain.from_iterable(matrix), columns, strict=True)
def transpose(matrix):
"Swap the rows and columns of a 2-D matrix."
# transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33)
return zip(*matrix, stri... | have a given number of columns." # reshape([(0, 1), (2, 3), (4, 5)], 3) → (0, 1, 2) (3, 4, 5) return batched(chain.from_iterable(matrix), columns, strict=True)
def transpose(matrix):
"Swap the rows and columns of a 2-D matrix."
# transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33)
return zip(*matrix, stri... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aba73e70-b145-42df-9c52-fb80bd0845ab | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,096 | supabase-export-v2 | eb85c650c390c4fd | Make an iterator that returns elements from the *iterable* as long as the *predicate* is true. Roughly equivalent to::
def takewhile(predicate, iterable):
# takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4
for x in iterable:
if not predicate(x):
break
yield x | trusted_official_docs | CPython Docs | Make an iterator that returns elements from the *iterable* as long as the *predicate* is true. Roughly equivalent to::
def takewhile(predicate, iterable):
# takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4
for x in iterable:
if not predicate(x):
break
yield x | Make an iterator that returns elements from the *iterable* as long as the *predicate* is true. Roughly equivalent to::
def takewhile(predicate, iterable):
# takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4
for x in iterable:
if not predicate(x):
break
yield x | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ae91c99d-3b82-46ae-b7df-f30bb41bfe97 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,071 | supabase-export-v2 | 6cfe874722a73456 | indices = list(range(n)) cycles = list(range(n, n-r, -1)) yield tuple(pool[i] for i in indices[:r])
while n:
for i in reversed(range(r)):
cycles[i] -= 1
if cycles[i] == 0:
indices[i:] = indices[i+1:] + indices[i:i+1]
cycles[i] = n - i
else:
j = cycles[i]
indices[i], indices[-j] = indices[-j], indices[i]
yield ... | trusted_official_docs | CPython Docs | indices = list(range(n)) cycles = list(range(n, n-r, -1)) yield tuple(pool[i] for i in indices[:r])
while n:
for i in reversed(range(r)):
cycles[i] -= 1
if cycles[i] == 0:
indices[i:] = indices[i+1:] + indices[i:i+1]
cycles[i] = n - i
else:
j = cycles[i]
indices[i], indices[-j] = indices[-j], indices[i]
yield ... | indices = list(range(n)) cycles = list(range(n, n-r, -1)) yield tuple(pool[i] for i in indices[:r])
while n:
for i in reversed(range(r)):
cycles[i] -= 1
if cycles[i] == 0:
indices[i:] = indices[i+1:] + indices[i:i+1]
cycles[i] = n - i
else:
j = cycles[i]
indices[i], indices[-j] = indices[-j], indices[i]
yield ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aec48d99-a763-49c6-a336-95c788c8c5e6 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,266 | supabase-export-v2 | 239cd3379c6e6682 | >>> iterable = 'abcde' >>> r = 3 >>> combos = list(combinations(iterable, r)) >>> all(nth_combination(iterable, r, i) == comb for i, comb in enumerate(combos)) True
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI' | trusted_official_docs | CPython Docs | >>> iterable = 'abcde' >>> r = 3 >>> combos = list(combinations(iterable, r)) >>> all(nth_combination(iterable, r, i) == comb for i, comb in enumerate(combos)) True
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI' | >>> iterable = 'abcde' >>> r = 3 >>> combos = list(combinations(iterable, r)) >>> all(nth_combination(iterable, r, i) == comb for i, comb in enumerate(combos)) True
>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b0e56b18-6877-48b7-8661-416c7e47142a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,255 | supabase-export-v2 | 934a953a664a2509 | Note that the true iterator must be fully consumed before the remainder iterator can generate valid results. """ it = iter(it) transition = []
def true_iterator():
for elem in it:
if predicate(elem):
yield elem
else:
transition.append(elem)
return | trusted_official_docs | CPython Docs | Note that the true iterator must be fully consumed before the remainder iterator can generate valid results. """ it = iter(it) transition = []
def true_iterator():
for elem in it:
if predicate(elem):
yield elem
else:
transition.append(elem)
return | Note that the true iterator must be fully consumed before the remainder iterator can generate valid results. """ it = iter(it) transition = []
def true_iterator():
for elem in it:
if predicate(elem):
yield elem
else:
transition.append(elem)
return | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b11afcbe-606b-4e46-8f0c-a61493f843d9 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,961 | supabase-export-v2 | 67d71b64e651b234 | → 1 3 6 10 15 # accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115 # accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120
iterator = iter(iterable)
total = initial
if initial is None:
try:
total = next(iterator)
except StopIteration:
return | trusted_official_docs | CPython Docs | → 1 3 6 10 15 # accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115 # accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120
iterator = iter(iterable)
total = initial
if initial is None:
try:
total = next(iterator)
except StopIteration:
return | → 1 3 6 10 15 # accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115 # accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120
iterator = iter(iterable)
total = initial
if initial is None:
try:
total = next(iterator)
except StopIteration:
return | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b1a5c925-2669-40a1-8a6f-f0add8bb4f6a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,991 | supabase-export-v2 | 5319b8547cb9fc04 | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within each combinat... | trusted_official_docs | CPython Docs | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within each combinat... | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within each combinat... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b2fb4512-463e-4bfc-8ab3-f16a2a4b97eb | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,014 | supabase-export-v2 | 6000523f3cffd5e8 | counting with floating-point numbers, better accuracy can sometimes be achieved by substituting multiplicative code such as: ``(start + step * i for i in count())``.
.. versionchanged:: 3.1
Added *step* argument and allowed non-integer arguments. | trusted_official_docs | CPython Docs | counting with floating-point numbers, better accuracy can sometimes be achieved by substituting multiplicative code such as: ``(start + step * i for i in count())``.
.. versionchanged:: 3.1
Added *step* argument and allowed non-integer arguments. | counting with floating-point numbers, better accuracy can sometimes be achieved by substituting multiplicative code such as: ``(start + step * i for i in count())``.
.. versionchanged:: 3.1
Added *step* argument and allowed non-integer arguments. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b36d35d6-3630-4283-8e05-878f92ddf08c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,229 | supabase-export-v2 | 50a42662a5eba281 | inputs are consumed lazily >>> input_iterators = list(map(iter, ['abcd', 'ef', '', 'ghijk', 'l', 'mnopqr'])) >>> output_iterator = roundrobin(*input_iterators) >>> ''.join(islice(output_iterator, 10)) 'aeglmbfhnc' >>> ''.join(chain(*input_iterators)) 'dijkopqr'
>>> list(subslices('ABCD'))
['A', 'AB', 'ABC', 'ABCD', 'B... | trusted_official_docs | CPython Docs | inputs are consumed lazily >>> input_iterators = list(map(iter, ['abcd', 'ef', '', 'ghijk', 'l', 'mnopqr'])) >>> output_iterator = roundrobin(*input_iterators) >>> ''.join(islice(output_iterator, 10)) 'aeglmbfhnc' >>> ''.join(chain(*input_iterators)) 'dijkopqr'
>>> list(subslices('ABCD'))
['A', 'AB', 'ABC', 'ABCD', 'B... | inputs are consumed lazily >>> input_iterators = list(map(iter, ['abcd', 'ef', '', 'ghijk', 'l', 'mnopqr'])) >>> output_iterator = roundrobin(*input_iterators) >>> ''.join(islice(output_iterator, 10)) 'aeglmbfhnc' >>> ''.join(chain(*input_iterators)) 'dijkopqr'
>>> list(subslices('ABCD'))
['A', 'AB', 'ABC', 'ABCD', 'B... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b423a14a-f01b-4021-a72a-2a97e97da403 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,957 | supabase-export-v2 | a09675a5730668cf | Make an iterator that returns accumulated sums or accumulated results from other binary functions.
The *function* defaults to addition. The *function* should accept
two arguments, an accumulated total and a value from the *iterable*. | trusted_official_docs | CPython Docs | Make an iterator that returns accumulated sums or accumulated results from other binary functions.
The *function* defaults to addition. The *function* should accept
two arguments, an accumulated total and a value from the *iterable*. | Make an iterator that returns accumulated sums or accumulated results from other binary functions.
The *function* defaults to addition. The *function* should accept
two arguments, an accumulated total and a value from the *iterable*. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b4ac7a27-3449-4a98-bcb4-57f1c16cb303 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,064 | supabase-export-v2 | 0e87201179ff94e9 | If *r* is not specified or is ``None``, then *r* defaults to the length of the *iterable* and all possible full-length permutations are generated.
The output is a subsequence of :func:`product` where entries with
repeated elements have been filtered out. The length of the output is
given by :func:`math.perm` which co... | trusted_official_docs | CPython Docs | If *r* is not specified or is ``None``, then *r* defaults to the length of the *iterable* and all possible full-length permutations are generated.
The output is a subsequence of :func:`product` where entries with
repeated elements have been filtered out. The length of the output is
given by :func:`math.perm` which co... | If *r* is not specified or is ``None``, then *r* defaults to the length of the *iterable* and all possible full-length permutations are generated.
The output is a subsequence of :func:`product` where entries with
repeated elements have been filtered out. The length of the output is
given by :func:`math.perm` which co... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b5c7ec06-9f7b-4c55-b706-cba6b3c63ff5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,106 | supabase-export-v2 | bd21cceb90599060 | def __next__(self): link = self.link if link[1] is None: link[0] = next(self.iterator) link[1] = [None, None] value, self.link = link return value
When the input *iterable* is already a tee iterator object, all
members of the return tuple are constructed as if they had been
produced by the upstream :func:`tee` call. ... | trusted_official_docs | CPython Docs | def __next__(self): link = self.link if link[1] is None: link[0] = next(self.iterator) link[1] = [None, None] value, self.link = link return value
When the input *iterable* is already a tee iterator object, all
members of the return tuple are constructed as if they had been
produced by the upstream :func:`tee` call. ... | def __next__(self): link = self.link if link[1] is None: link[0] = next(self.iterator) link[1] = [None, None] value, self.link = link return value
When the input *iterable* is already a tee iterator object, all
members of the return tuple are constructed as if they had been
produced by the upstream :func:`tee` call. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b6308d85-ea87-444f-a6f4-4b3bf43a127c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,989 | supabase-export-v2 | 421bc8001b1a5710 | Return *r* length subsequences of elements from the input *iterable*.
The output is a subsequence of :func:`product` keeping only entries that
are subsequences of the *iterable*. The length of the output is given
by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r
≤ n`` or zero when ``r > n``. | trusted_official_docs | CPython Docs | Return *r* length subsequences of elements from the input *iterable*.
The output is a subsequence of :func:`product` keeping only entries that
are subsequences of the *iterable*. The length of the output is given
by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r
≤ n`` or zero when ``r > n``. | Return *r* length subsequences of elements from the input *iterable*.
The output is a subsequence of :func:`product` keeping only entries that
are subsequences of the *iterable*. The length of the output is given
by :func:`math.comb` which computes ``n! / r! / (n - r)!`` when ``0 ≤ r
≤ n`` or zero when ``r > n``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b6c88357-d6d8-48a4-a622-a8acdb2b8416 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,202 | supabase-export-v2 | b567ee7616ea9492 | equivalence class is used to disprove >>> # the assertion that all elements are equal. >>> it = iter('aaabbbccc') >>> all_equal(it) False >>> ''.join(it) 'bbccc'
>>> quantify(range(99), lambda x: x%2==0)
50
>>> quantify([True, False, False, True, True])
3
>>> quantify(range(12), predicate=lambda x: x%2==1)
6 | trusted_official_docs | CPython Docs | equivalence class is used to disprove >>> # the assertion that all elements are equal. >>> it = iter('aaabbbccc') >>> all_equal(it) False >>> ''.join(it) 'bbccc'
>>> quantify(range(99), lambda x: x%2==0)
50
>>> quantify([True, False, False, True, True])
3
>>> quantify(range(12), predicate=lambda x: x%2==1)
6 | equivalence class is used to disprove >>> # the assertion that all elements are equal. >>> it = iter('aaabbbccc') >>> all_equal(it) False >>> ''.join(it) 'bbccc'
>>> quantify(range(99), lambda x: x%2==0)
50
>>> quantify([True, False, False, True, True])
3
>>> quantify(range(12), predicate=lambda x: x%2==1)
6 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bc4614b9-94e4-4eae-ab81-9d543486ea72 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,190 | supabase-export-v2 | 90d7f8c3bce7a612 | >>> import operator >>> for cube in map(operator.pow, range(1,4), repeat(3)): ... print(cube) ... 1 8 27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
... print(name.title())
... Alex
Laura
Martin
Wal... | trusted_official_docs | CPython Docs | >>> import operator >>> for cube in map(operator.pow, range(1,4), repeat(3)): ... print(cube) ... 1 8 27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
... print(name.title())
... Alex
Laura
Martin
Wal... | >>> import operator >>> for cube in map(operator.pow, range(1,4), repeat(3)): ... print(cube) ... 1 8 27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
... print(name.title())
... Alex
Laura
Martin
Wal... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bdf96f97-f1ed-412c-9f9d-8293ca6c1bd8 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,063 | supabase-export-v2 | 57d82c8ddd2003ca | Return successive *r* length `permutations of elements <https://www.britannica.com/science/permutation>`_ from the *iterable*.
If *r* is not specified or is ``None``, then *r* defaults to the length
of the *iterable* and all possible full-length permutations
are generated. | trusted_official_docs | CPython Docs | Return successive *r* length `permutations of elements <https://www.britannica.com/science/permutation>`_ from the *iterable*.
If *r* is not specified or is ``None``, then *r* defaults to the length
of the *iterable* and all possible full-length permutations
are generated. | Return successive *r* length `permutations of elements <https://www.britannica.com/science/permutation>`_ from the *iterable*.
If *r* is not specified or is ``None``, then *r* defaults to the length
of the *iterable* and all possible full-length permutations
are generated. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
be9264f9-438f-4c1b-9d7c-cb9894e9b933 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,003 | supabase-export-v2 | 5706830c1b5e9448 | def combinations_with_replacement(iterable, r): # combinations_with_replacement('ABC', 2) → AA AB AC BB BC CC
pool = tuple(iterable)
n = len(pool)
if not n and r:
return
indices = [0] * r | trusted_official_docs | CPython Docs | def combinations_with_replacement(iterable, r): # combinations_with_replacement('ABC', 2) → AA AB AC BB BC CC
pool = tuple(iterable)
n = len(pool)
if not n and r:
return
indices = [0] * r | def combinations_with_replacement(iterable, r): # combinations_with_replacement('ABC', 2) → AA AB AC BB BC CC
pool = tuple(iterable)
n = len(pool)
if not n and r:
return
indices = [0] * r | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
be933abf-e7db-4e97-bdc7-30870312c548 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,023 | supabase-export-v2 | d2606d76238bf8af | Make an iterator that drops elements from the *iterable* while the *predicate* is true and afterwards returns every element. Roughly equivalent to::
def dropwhile(predicate, iterable):
# dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8 | trusted_official_docs | CPython Docs | Make an iterator that drops elements from the *iterable* while the *predicate* is true and afterwards returns every element. Roughly equivalent to::
def dropwhile(predicate, iterable):
# dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8 | Make an iterator that drops elements from the *iterable* while the *predicate* is true and afterwards returns every element. Roughly equivalent to::
def dropwhile(predicate, iterable):
# dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bf3c640e-ae08-44d2-8749-b21b6c397294 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,149 | supabase-export-v2 | a0c9b80c3f982055 | None: for element in filterfalse(seen.__contains__, iterable): seen.add(element) yield element else: for element in iterable: k = key(element) if k not in seen: seen.add(k) yield element
def unique(iterable, key=None, reverse=False):
"Yield unique elements in sorted order. Supports unhashable inputs."
# unique([[1, 2... | trusted_official_docs | CPython Docs | None: for element in filterfalse(seen.__contains__, iterable): seen.add(element) yield element else: for element in iterable: k = key(element) if k not in seen: seen.add(k) yield element
def unique(iterable, key=None, reverse=False):
"Yield unique elements in sorted order. Supports unhashable inputs."
# unique([[1, 2... | None: for element in filterfalse(seen.__contains__, iterable): seen.add(element) yield element else: for element in iterable: k = key(element) if k not in seen: seen.add(k) yield element
def unique(iterable, key=None, reverse=False):
"Yield unique elements in sorted order. Supports unhashable inputs."
# unique([[1, 2... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c00aaeee-6329-4975-a637-292ef383ee1c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,173 | supabase-export-v2 | 994efbd4bb37b375 | 5 # polynomial_eval([1, -4, -17, 60], x=5) → 0 n = len(coefficients) if not n: return type(x)(0) powers = map(pow, repeat(x), reversed(range(n))) return sumprod(coefficients, powers)
def polynomial_derivative(coefficients):
"""Compute the first derivative of a polynomial. | trusted_official_docs | CPython Docs | 5 # polynomial_eval([1, -4, -17, 60], x=5) → 0 n = len(coefficients) if not n: return type(x)(0) powers = map(pow, repeat(x), reversed(range(n))) return sumprod(coefficients, powers)
def polynomial_derivative(coefficients):
"""Compute the first derivative of a polynomial. | 5 # polynomial_eval([1, -4, -17, 60], x=5) → 0 n = len(coefficients) if not n: return type(x)(0) powers = map(pow, repeat(x), reversed(range(n))) return sumprod(coefficients, powers)
def polynomial_derivative(coefficients):
"""Compute the first derivative of a polynomial. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c10ce425-2133-4068-a7ea-2a425c06b26f | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,946 | supabase-export-v2 | 9275aad7d8cd90f9 | F`` :func:`count` [start[, step]] start, start+step, start+2*step, ... ``count(10) → 10 11 12 13 14 ...`` :func:`cycle` p p0, p1, ... plast, p0, p1, ...
``cycle('ABCD') → A B C D A B C D ...``
:func:`dropwhile` predicate, seq seq[n], seq[n+1], starting when predicate fails ``dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 ... | trusted_official_docs | CPython Docs | F`` :func:`count` [start[, step]] start, start+step, start+2*step, ... ``count(10) → 10 11 12 13 14 ...`` :func:`cycle` p p0, p1, ... plast, p0, p1, ...
``cycle('ABCD') → A B C D A B C D ...``
:func:`dropwhile` predicate, seq seq[n], seq[n+1], starting when predicate fails ``dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 ... | F`` :func:`count` [start[, step]] start, start+step, start+2*step, ... ``count(10) → 10 11 12 13 14 ...`` :func:`cycle` p p0, p1, ... plast, p0, p1, ...
``cycle('ABCD') → A B C D A B C D ...``
:func:`dropwhile` predicate, seq seq[n], seq[n+1], starting when predicate fails ``dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c4831542-5061-46ee-ba5e-4da05fd8129c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,211 | supabase-export-v2 | eee5bd425a2e0246 | Fraction(2, 3)) Fraction(0, 1) >>> polynomial_eval([], Decimal('1.75')) Decimal('0') >>> polynomial_eval([11], 7) == 11 True >>> polynomial_eval([11, 2], 7) == 11 * 7 + 2 True
>>> polynomial_from_roots([5, -4, 3])
[1, -4, -17, 60]
>>> factored = lambda x: (x - 5) * (x + 4) * (x - 3)
>>> expanded = lambda x: x**3 -4*... | trusted_official_docs | CPython Docs | Fraction(2, 3)) Fraction(0, 1) >>> polynomial_eval([], Decimal('1.75')) Decimal('0') >>> polynomial_eval([11], 7) == 11 True >>> polynomial_eval([11, 2], 7) == 11 * 7 + 2 True
>>> polynomial_from_roots([5, -4, 3])
[1, -4, -17, 60]
>>> factored = lambda x: (x - 5) * (x + 4) * (x - 3)
>>> expanded = lambda x: x**3 -4*... | Fraction(2, 3)) Fraction(0, 1) >>> polynomial_eval([], Decimal('1.75')) Decimal('0') >>> polynomial_eval([11], 7) == 11 True >>> polynomial_eval([11, 2], 7) == 11 * 7 + 2 True
>>> polynomial_from_roots([5, -4, 3])
[1, -4, -17, 60]
>>> factored = lambda x: (x - 5) * (x + 4) * (x - 3)
>>> expanded = lambda x: x**3 -4*... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c535dc50-7956-4a79-8bec-ea6ba19dd294 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,951 | supabase-export-v2 | 39fff4461b739bee | :func:`combinations` p, r r-length tuples, in sorted order, no repeated elements :func:`combinations_with_replacement` p, r r-length tuples, in sorted order, with repeated elements ============================================== ==================== =============================================================
=========... | trusted_official_docs | CPython Docs | :func:`combinations` p, r r-length tuples, in sorted order, no repeated elements :func:`combinations_with_replacement` p, r r-length tuples, in sorted order, with repeated elements ============================================== ==================== =============================================================
=========... | :func:`combinations` p, r r-length tuples, in sorted order, no repeated elements :func:`combinations_with_replacement` p, r r-length tuples, in sorted order, with repeated elements ============================================== ==================== =============================================================
=========... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5a224f3-4bc5-4017-9971-6b04b8938dc2 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,065 | supabase-export-v2 | 1c2999074797d0bd | the output is given by :func:`math.perm` which computes ``n! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The permutation tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | trusted_official_docs | CPython Docs | the output is given by :func:`math.perm` which computes ``n! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The permutation tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | the output is given by :func:`math.perm` which computes ``n! / (n - r)!`` when ``0 ≤ r ≤ n`` or zero when ``r > n``.
The permutation tuples are emitted in lexicographic order according to
the order of the input *iterable*. If the input *iterable* is sorted,
the output tuples will be produced in sorted order. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5cebbd0-0bd0-4d05-a6f3-720ac1ba1890 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,237 | supabase-export-v2 | 61ad54734bc57667 | >>> first_true('ABC0DEF1', '9', str.isdigit) '0' >>> # Verify that inputs are consumed lazily >>> it = iter('ABC0DEF1') >>> first_true(it, predicate=str.isdigit) '0' >>> ''.join(it) 'DEF1'
>>> multinomial(5, 2, 2, 1, 1)
83160
>>> word = 'coffee'
>>> multinomial(*Counter(word).values()) == len(set(permutations(word))... | trusted_official_docs | CPython Docs | >>> first_true('ABC0DEF1', '9', str.isdigit) '0' >>> # Verify that inputs are consumed lazily >>> it = iter('ABC0DEF1') >>> first_true(it, predicate=str.isdigit) '0' >>> ''.join(it) 'DEF1'
>>> multinomial(5, 2, 2, 1, 1)
83160
>>> word = 'coffee'
>>> multinomial(*Counter(word).values()) == len(set(permutations(word))... | >>> first_true('ABC0DEF1', '9', str.isdigit) '0' >>> # Verify that inputs are consumed lazily >>> it = iter('ABC0DEF1') >>> first_true(it, predicate=str.isdigit) '0' >>> ''.join(it) 'DEF1'
>>> multinomial(5, 2, 2, 1, 1)
83160
>>> word = 'coffee'
>>> multinomial(*Counter(word).values()) == len(set(permutations(word))... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5deb633-1920-4c03-9386-b4d4e5792797 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,208 | supabase-export-v2 | e72244cd8e5cded0 | iter([1, 2, 3]) >>> input2 = iter([11, 22, 33]) >>> output_iterator = transpose([input1, input2]) >>> next(output_iterator) (1, 11) >>> list(zip(input1, input2)) [(2, 22), (3, 33)]
>>> list(matmul([(7, 5), (3, 5)], [[2, 5], [7, 9]]))
[(49, 80), (41, 60)]
>>> list(matmul([[2, 5], [7, 9], [3, 4]], [[7, 11, 5, 4, 9], [3... | trusted_official_docs | CPython Docs | iter([1, 2, 3]) >>> input2 = iter([11, 22, 33]) >>> output_iterator = transpose([input1, input2]) >>> next(output_iterator) (1, 11) >>> list(zip(input1, input2)) [(2, 22), (3, 33)]
>>> list(matmul([(7, 5), (3, 5)], [[2, 5], [7, 9]]))
[(49, 80), (41, 60)]
>>> list(matmul([[2, 5], [7, 9], [3, 4]], [[7, 11, 5, 4, 9], [3... | iter([1, 2, 3]) >>> input2 = iter([11, 22, 33]) >>> output_iterator = transpose([input1, input2]) >>> next(output_iterator) (1, 11) >>> list(zip(input1, input2)) [(2, 22), (3, 33)]
>>> list(matmul([(7, 5), (3, 5)], [[2, 5], [7, 9]]))
[(49, 80), (41, 60)]
>>> list(matmul([[2, 5], [7, 9], [3, 4]], [[7, 11, 5, 4, 9], [3... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c76ed9a2-ce02-44d9-8d27-0382164ab55a | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,942 | supabase-export-v2 | de6d5abd778296f5 | useful by themselves or in combination. Together, they form an "iterator algebra" making it possible to construct specialized tools succinctly and efficiently in pure Python.
For instance, SML provides a tabulation tool: ``tabulate(f)`` which produces a
sequence ``f(0), f(1), ...``. The same effect can be achieved in P... | trusted_official_docs | CPython Docs | useful by themselves or in combination. Together, they form an "iterator algebra" making it possible to construct specialized tools succinctly and efficiently in pure Python.
For instance, SML provides a tabulation tool: ``tabulate(f)`` which produces a
sequence ``f(0), f(1), ...``. The same effect can be achieved in P... | useful by themselves or in combination. Together, they form an "iterator algebra" making it possible to construct specialized tools succinctly and efficiently in pure Python.
For instance, SML provides a tabulation tool: ``tabulate(f)`` which produces a
sequence ``f(0), f(1), ...``. The same effect can be achieved in P... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c859e5ff-8c7e-4f88-b57f-c9e64f11f4eb | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,231 | supabase-export-v2 | 7ef84d6aa9331c36 | = ' '.join(map(''.join, derangements(seq2))) >>> result2 'XAxB XBxA XxAB BAxX BxAX BxXA xAXB xBAX xBXA' >>> result1 == result2 False >>> result1.casefold() == result2.casefold() True
>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> all(len(list(powerset(range(n)))) == 2**n for... | trusted_official_docs | CPython Docs | = ' '.join(map(''.join, derangements(seq2))) >>> result2 'XAxB XBxA XxAB BAxX BxAX BxXA xAXB xBAX xBXA' >>> result1 == result2 False >>> result1.casefold() == result2.casefold() True
>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> all(len(list(powerset(range(n)))) == 2**n for... | = ' '.join(map(''.join, derangements(seq2))) >>> result2 'XAxB XBxA XxAB BAxX BxAX BxXA xAXB xBAX xBXA' >>> result1 == result2 False >>> result1.casefold() == result2.casefold() True
>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> all(len(list(powerset(range(n)))) == 2**n for... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c87f04fe-0167-48c6-b1e0-36c0d1a599b6 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,092 | supabase-export-v2 | 1d3366dd98910618 | an iterator that computes the *function* using arguments obtained from the *iterable*. Used instead of :func:`map` when argument parameters have already been "pre-zipped" into tuples.
The difference between :func:`map` and :func:`starmap` parallels the
distinction between ``function(a,b)`` and ``function(*c)``. Roughl... | trusted_official_docs | CPython Docs | an iterator that computes the *function* using arguments obtained from the *iterable*. Used instead of :func:`map` when argument parameters have already been "pre-zipped" into tuples.
The difference between :func:`map` and :func:`starmap` parallels the
distinction between ``function(a,b)`` and ``function(*c)``. Roughl... | an iterator that computes the *function* using arguments obtained from the *iterable*. Used instead of :func:`map` when argument parameters have already been "pre-zipped" into tuples.
The difference between :func:`map` and :func:`starmap` parallels the
distinction between ``function(a,b)`` and ``function(*c)``. Roughl... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c8ef17db-f9b0-4018-ae97-2cb89c5479a7 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,133 | supabase-export-v2 | 1af710e6b574d698 | import reduce from heapq import heappush, heappushpop, heappush_max, heappushpop_max from math import comb, isqrt, prod, sumprod from operator import getitem, is_not, itemgetter, mul, neg, truediv
# ==== Basic one liners ==== | trusted_official_docs | CPython Docs | import reduce from heapq import heappush, heappushpop, heappush_max, heappushpop_max from math import comb, isqrt, prod, sumprod from operator import getitem, is_not, itemgetter, mul, neg, truediv
# ==== Basic one liners ==== | import reduce from heapq import heappush, heappushpop, heappush_max, heappushpop_max from math import comb, isqrt, prod, sumprod from operator import getitem, is_not, itemgetter, mul, neg, truediv
# ==== Basic one liners ==== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c99f494e-6c7c-4dff-8e13-627d76d13963 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,176 | supabase-export-v2 | 92175d75069cbd9c | # ==== Number theory ====
def sieve(n):
"Primes less than n."
# sieve(30) → 2 3 5 7 11 13 17 19 23 29
if n > 2:
yield 2
data = bytearray((0, 1)) * (n // 2)
for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1):
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
yield from iter_index(data, 1, start=3) | trusted_official_docs | CPython Docs | # ==== Number theory ====
def sieve(n):
"Primes less than n."
# sieve(30) → 2 3 5 7 11 13 17 19 23 29
if n > 2:
yield 2
data = bytearray((0, 1)) * (n // 2)
for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1):
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
yield from iter_index(data, 1, start=3) | # ==== Number theory ====
def sieve(n):
"Primes less than n."
# sieve(30) → 2 3 5 7 11 13 17 19 23 29
if n > 2:
yield 2
data = bytearray((0, 1)) * (n // 2)
for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1):
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
yield from iter_index(data, 1, start=3) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c9b8096a-32c3-4aa1-a712-0687170a7018 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,210 | supabase-export-v2 | e9c936ba5fa39228 | >>> kernel_iterator = iter([1, 2, 3]) >>> output_iterator = convolve(signal_iterator, kernel_iterator) >>> list(kernel_iterator) [] >>> next(output_iterator) 10 >>> next(output_iterator) 40 >>> list(signal_iterator) [30, 40, 50]
>>> from fractions import Fraction
>>> from decimal import Decimal
>>> polynomial_eval([1... | trusted_official_docs | CPython Docs | >>> kernel_iterator = iter([1, 2, 3]) >>> output_iterator = convolve(signal_iterator, kernel_iterator) >>> list(kernel_iterator) [] >>> next(output_iterator) 10 >>> next(output_iterator) 40 >>> list(signal_iterator) [30, 40, 50]
>>> from fractions import Fraction
>>> from decimal import Decimal
>>> polynomial_eval([1... | >>> kernel_iterator = iter([1, 2, 3]) >>> output_iterator = convolve(signal_iterator, kernel_iterator) >>> list(kernel_iterator) [] >>> next(output_iterator) 10 >>> next(output_iterator) 40 >>> list(signal_iterator) [30, 40, 50]
>>> from fractions import Fraction
>>> from decimal import Decimal
>>> polynomial_eval([1... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cad17171-2a55-48d8-9619-a551ab0ba20c | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,199 | supabase-export-v2 | 779e2f7540f63f61 | list(tail(3, 'ABCDEFG')) ['E', 'F', 'G'] >>> # Verify the input is consumed greedily >>> input_iterator = iter('ABCDEFG') >>> output_iterator = tail(3, input_iterator) >>> list(input_iterator) []
>>> it = iter(range(10))
>>> consume(it, 3)
>>> # Verify the input is consumed lazily
>>> next(it)
3
>>> # Verify the i... | trusted_official_docs | CPython Docs | list(tail(3, 'ABCDEFG')) ['E', 'F', 'G'] >>> # Verify the input is consumed greedily >>> input_iterator = iter('ABCDEFG') >>> output_iterator = tail(3, input_iterator) >>> list(input_iterator) []
>>> it = iter(range(10))
>>> consume(it, 3)
>>> # Verify the input is consumed lazily
>>> next(it)
3
>>> # Verify the i... | list(tail(3, 'ABCDEFG')) ['E', 'F', 'G'] >>> # Verify the input is consumed greedily >>> input_iterator = iter('ABCDEFG') >>> output_iterator = tail(3, input_iterator) >>> list(input_iterator) []
>>> it = iter(range(10))
>>> consume(it, 3)
>>> # Verify the input is consumed lazily
>>> next(it)
3
>>> # Verify the i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb544d52-d1d3-4db0-b3c3-69dd1fe96768 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,033 | supabase-export-v2 | 5b652399a85d13b6 | .. function:: groupby(iterable, key=None)
Make an iterator that returns consecutive keys and groups from the *iterable*. The *key* is a function computing a key value for each element. If not
specified or is ``None``, *key* defaults to an identity function and returns
the element unchanged. Generally, the iterable ne... | trusted_official_docs | CPython Docs | .. function:: groupby(iterable, key=None)
Make an iterator that returns consecutive keys and groups from the *iterable*. The *key* is a function computing a key value for each element. If not
specified or is ``None``, *key* defaults to an identity function and returns
the element unchanged. Generally, the iterable ne... | .. function:: groupby(iterable, key=None)
Make an iterator that returns consecutive keys and groups from the *iterable*. The *key* is a function computing a key value for each element. If not
specified or is ``None``, *key* defaults to an identity function and returns
the element unchanged. Generally, the iterable ne... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cddcc235-8d0a-4d4b-8e16-372ca422cda0 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,066 | supabase-export-v2 | 6ea646a0beb9d08a | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within a permutation... | trusted_official_docs | CPython Docs | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within a permutation... | lexicographic order according to the order of the input *iterable*. If the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their
value. If the input elements are unique, there will be no repeated
values within a permutation... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cee4058e-607f-4f9c-a263-ad3fa99688c5 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,218 | supabase-export-v2 | cd23f7b1af9010c6 | 168 >>> len(list(sieve(10_000))) 1229 >>> len(list(sieve(100_000))) 9592 >>> len(list(sieve(1_000_000))) 78498 >>> carmichael = {561, 1105, 1729, 2465, 2821, 6601, 8911} # https://oeis.org/A002997 >>> set(sieve(10_000)).isdisjoint(carmichael) True
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, ... | trusted_official_docs | CPython Docs | 168 >>> len(list(sieve(10_000))) 1229 >>> len(list(sieve(100_000))) 9592 >>> len(list(sieve(1_000_000))) 78498 >>> carmichael = {561, 1105, 1729, 2465, 2821, 6601, 8911} # https://oeis.org/A002997 >>> set(sieve(10_000)).isdisjoint(carmichael) True
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, ... | 168 >>> len(list(sieve(10_000))) 1229 >>> len(list(sieve(100_000))) 9592 >>> len(list(sieve(1_000_000))) 78498 >>> carmichael = {561, 1105, 1729, 2465, 2821, 6601, 8911} # https://oeis.org/A002997 >>> set(sieve(10_000)).isdisjoint(carmichael) True
>>> small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cefc55f6-bea1-4bab-9d27-524ee8163766 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,200 | supabase-export-v2 | 5fb396b5cc98dd00 | >>> # Verify the input is consumed lazily >>> next(it) 3 >>> # Verify the input is consumed completely >>> consume(it) >>> next(it, 'Done') 'Done'
>>> nth('abcde', 3)
'd'
>>> nth('abcde', 9) is None
True
>>> # Verify that the input is consumed lazily
>>> it = iter('abcde')
>>> nth(it, 2)
'c'
>>> list(it)
['d',... | trusted_official_docs | CPython Docs | >>> # Verify the input is consumed lazily >>> next(it) 3 >>> # Verify the input is consumed completely >>> consume(it) >>> next(it, 'Done') 'Done'
>>> nth('abcde', 3)
'd'
>>> nth('abcde', 9) is None
True
>>> # Verify that the input is consumed lazily
>>> it = iter('abcde')
>>> nth(it, 2)
'c'
>>> list(it)
['d',... | >>> # Verify the input is consumed lazily >>> next(it) 3 >>> # Verify the input is consumed completely >>> consume(it) >>> next(it, 'Done') 'Done'
>>> nth('abcde', 3)
'd'
>>> nth('abcde', 9) is None
True
>>> # Verify that the input is consumed lazily
>>> it = iter('abcde')
>>> nth(it, 2)
'c'
>>> list(it)
['d',... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d25fbca5-b996-4375-a307-6c56cb71dc26 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,178 | supabase-export-v2 | 16d69672dbe94b69 | in sieve(isqrt(n) + 1): while not n % prime: yield prime n //= prime if n == 1: return if n > 1: yield n
def is_prime(n):
"Return True if n is prime."
# is_prime(1_000_000_000_000_403) → True
return n > 1 and next(factor(n)) == n | trusted_official_docs | CPython Docs | in sieve(isqrt(n) + 1): while not n % prime: yield prime n //= prime if n == 1: return if n > 1: yield n
def is_prime(n):
"Return True if n is prime."
# is_prime(1_000_000_000_000_403) → True
return n > 1 and next(factor(n)) == n | in sieve(isqrt(n) + 1): while not n % prime: yield prime n //= prime if n == 1: return if n > 1: yield n
def is_prime(n):
"Return True if n is prime."
# is_prime(1_000_000_000_000_403) → True
return n > 1 and next(factor(n)) == n | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d26a000e-c47e-44d0-8bb3-ca359fe44d52 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,068 | supabase-export-v2 | 05a29fe137586417 | Roughly equivalent to::
def permutations(iterable, r=None):
# permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) → 012 021 102 120 201 210 | trusted_official_docs | CPython Docs | Roughly equivalent to::
def permutations(iterable, r=None):
# permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) → 012 021 102 120 201 210 | Roughly equivalent to::
def permutations(iterable, r=None):
# permutations('ABCD', 2) → AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) → 012 021 102 120 201 210 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d2cbeb7a-5aed-4a6c-9bf9-9ea6686ca474 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,267 | supabase-export-v2 | a267752c602b0568 | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) 'dEfGhI'
>>> def is_odd(x):
... return x % 2 == 1
... >>> evens, odds = partition(is_odd, range(10))
>>> list(evens)
[0, 2, 4, 6, 8]
>>> list(odds)
[1, 3, 5, 7, 9]
>>> # Ver... | trusted_official_docs | CPython Docs | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) 'dEfGhI'
>>> def is_odd(x):
... return x % 2 == 1
... >>> evens, odds = partition(is_odd, range(10))
>>> list(evens)
[0, 2, 4, 6, 8]
>>> list(odds)
[1, 3, 5, 7, 9]
>>> # Ver... | >>> it = iter('ABCdEfGhI') >>> all_upper, remainder = before_and_after(str.isupper, it) >>> ''.join(all_upper) 'ABC' >>> ''.join(remainder) 'dEfGhI'
>>> def is_odd(x):
... return x % 2 == 1
... >>> evens, odds = partition(is_odd, range(10))
>>> list(evens)
[0, 2, 4, 6, 8]
>>> list(odds)
[1, 3, 5, 7, 9]
>>> # Ver... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5c4fd63-5537-4a2b-95ae-5921dbc98e6b | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,191 | supabase-export-v2 | 3c5a31993270fc99 | 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele'] >>> for name in islice(reportlines, 3, None, 2): ... print(name.title()) ... Alex Laura Martin Walter Samuele
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> f... | trusted_official_docs | CPython Docs | 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele'] >>> for name in islice(reportlines, 3, None, 2): ... print(name.title()) ... Alex Laura Martin Walter Samuele
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> f... | 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele'] >>> for name in islice(reportlines, 3, None, 2): ... print(name.title()) ... Alex Laura Martin Walter Samuele
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> f... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5c73797-f269-4f94-991e-59d1f6b3f5dc | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,167 | supabase-export-v2 | 7b3eb0ffc8044236 | def convolve(signal, kernel): """Discrete linear convolution of two iterables. Equivalent to polynomial multiplication.
Convolutions are mathematically commutative; however, the inputs are
evaluated differently. The signal is consumed lazily and can be
infinite. The kernel is fully consumed before the calculations be... | trusted_official_docs | CPython Docs | def convolve(signal, kernel): """Discrete linear convolution of two iterables. Equivalent to polynomial multiplication.
Convolutions are mathematically commutative; however, the inputs are
evaluated differently. The signal is consumed lazily and can be
infinite. The kernel is fully consumed before the calculations be... | def convolve(signal, kernel): """Discrete linear convolution of two iterables. Equivalent to polynomial multiplication.
Convolutions are mathematically commutative; however, the inputs are
evaluated differently. The signal is consumed lazily and can be
infinite. The kernel is fully consumed before the calculations be... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dac6c962-0b66-42d0-9c7f-c27fa20f606f | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,170 | supabase-export-v2 | 193728b63766ce5b | def polynomial_from_roots(roots): """Compute a polynomial's coefficients from its roots.
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
"""
# polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60]
factors = zip(repeat(1), map(neg, roots))
return list(reduce(convolve, factors, [1])) | trusted_official_docs | CPython Docs | def polynomial_from_roots(roots): """Compute a polynomial's coefficients from its roots.
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
"""
# polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60]
factors = zip(repeat(1), map(neg, roots))
return list(reduce(convolve, factors, [1])) | def polynomial_from_roots(roots): """Compute a polynomial's coefficients from its roots.
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
"""
# polynomial_from_roots([5, -4, 3]) → [1, -4, -17, 60]
factors = zip(repeat(1), map(neg, roots))
return list(reduce(convolve, factors, [1])) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dafb16b5-e6aa-45d2-b779-eb9cb569194e | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,040 | supabase-export-v2 | f8f31ce74bc143f3 | keyfunc = (lambda x: x) if key is None else key iterator = iter(iterable) exhausted = False
def _grouper(target_key):
nonlocal curr_value, curr_key, exhausted
yield curr_value
for curr_value in iterator:
curr_key = keyfunc(curr_value)
if curr_key != target_key:
return
yield curr_value
exhausted = True | trusted_official_docs | CPython Docs | keyfunc = (lambda x: x) if key is None else key iterator = iter(iterable) exhausted = False
def _grouper(target_key):
nonlocal curr_value, curr_key, exhausted
yield curr_value
for curr_value in iterator:
curr_key = keyfunc(curr_value)
if curr_key != target_key:
return
yield curr_value
exhausted = True | keyfunc = (lambda x: x) if key is None else key iterator = iter(iterable) exhausted = False
def _grouper(target_key):
nonlocal curr_value, curr_key, exhausted
yield curr_value
for curr_value in iterator:
curr_key = keyfunc(curr_value)
if curr_key != target_key:
return
yield curr_value
exhausted = True | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
db29b951-29a9-46b3-b464-33e7a56bce2d | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,194 | supabase-export-v2 | 5698391222f6831f | Now, we test all of the itertool recipes
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> # Verify that the input is consumed lazily
>>> it = iter('abcdef')
>>> take(3, it)
['a', 'b', 'c']
>>> list(it)
['d', 'e', 'f'] | trusted_official_docs | CPython Docs | Now, we test all of the itertool recipes
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> # Verify that the input is consumed lazily
>>> it = iter('abcdef')
>>> take(3, it)
['a', 'b', 'c']
>>> list(it)
['d', 'e', 'f'] | Now, we test all of the itertool recipes
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> # Verify that the input is consumed lazily
>>> it = iter('abcdef')
>>> take(3, it)
['a', 'b', 'c']
>>> list(it)
['d', 'e', 'f'] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dcdccc51-1791-44db-91a1-1ad8ce2180c3 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,177 | supabase-export-v2 | 3febc1586e294afd | // 2) for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1): data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p))) yield from iter_index(data, 1, start=3)
def factor(n):
"Prime factors of n."
# factor(99) → 3 3 11
# factor(1_000_000_000_000_007) → 47 59 360620266859
# factor(1_000_000_000_000_403) → 1000000000000... | trusted_official_docs | CPython Docs | // 2) for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1): data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p))) yield from iter_index(data, 1, start=3)
def factor(n):
"Prime factors of n."
# factor(99) → 3 3 11
# factor(1_000_000_000_000_007) → 47 59 360620266859
# factor(1_000_000_000_000_403) → 1000000000000... | // 2) for p in iter_index(data, 1, start=3, stop=isqrt(n) + 1): data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p))) yield from iter_index(data, 1, start=3)
def factor(n):
"Prime factors of n."
# factor(99) → 3 3 11
# factor(1_000_000_000_000_007) → 47 59 360620266859
# factor(1_000_000_000_000_403) → 1000000000000... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dd42b5f6-5092-4581-b5b8-8c47269522de | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,164 | supabase-export-v2 | 6aac23399ef0bfb0 | the rows and columns of a 2-D matrix." # transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33) return zip(*matrix, strict=True)
def matmul(m1, m2):
"Multiply two matrices."
# matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60)
n = len(m2[0])
return batched(starmap(sumprod, product(m1, transpose(... | trusted_official_docs | CPython Docs | the rows and columns of a 2-D matrix." # transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33) return zip(*matrix, strict=True)
def matmul(m1, m2):
"Multiply two matrices."
# matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60)
n = len(m2[0])
return batched(starmap(sumprod, product(m1, transpose(... | the rows and columns of a 2-D matrix." # transpose([(1, 2, 3), (11, 22, 33)]) → (1, 11) (2, 22) (3, 33) return zip(*matrix, strict=True)
def matmul(m1, m2):
"Multiply two matrices."
# matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]) → (49, 80) (41, 60)
n = len(m2[0])
return batched(starmap(sumprod, product(m1, transpose(... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dde87fe5-9828-4f88-a4e2-95130708865e | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 3,079 | supabase-export-v2 | fe85ee497ae9d600 | repeat=1): # product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
if repeat < 0:
raise ValueError('repeat argument cannot be negative')
pools = [tuple(pool) for pool in iterables] * repeat | trusted_official_docs | CPython Docs | repeat=1): # product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
if repeat < 0:
raise ValueError('repeat argument cannot be negative')
pools = [tuple(pool) for pool in iterables] * repeat | repeat=1): # product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
if repeat < 0:
raise ValueError('repeat argument cannot be negative')
pools = [tuple(pool) for pool in iterables] * repeat | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
deaca41c-a6e0-407b-9f9b-454227521f83 | CPython Docs | file://datasets/cpython/Doc/library/itertools.rst | unknown | 325025cd-dca2-4e2b-be43-fa8be886f8e7 | 2,958 | supabase-export-v2 | 976264dca553af7e | The *function* defaults to addition. The *function* should accept two arguments, an accumulated total and a value from the *iterable*.
If an *initial* value is provided, the accumulation will start with
that value and the output will have one more element than the input
iterable. | trusted_official_docs | CPython Docs | The *function* defaults to addition. The *function* should accept two arguments, an accumulated total and a value from the *iterable*.
If an *initial* value is provided, the accumulation will start with
that value and the output will have one more element than the input
iterable. | The *function* defaults to addition. The *function* should accept two arguments, an accumulated total and a value from the *iterable*.
If an *initial* value is provided, the accumulation will start with
that value and the output will have one more element than the input
iterable. | 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.