• Home
  • Raw
  • Download

Lines Matching refs:iterable

52 :func:`chain.from_iterable`     iterable                        p0, p1, ... plast, q0, q1, ...     …
56 :func:`groupby` iterable[, key] sub-iterators grouped by value of k…
58 :func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) …
95 .. function:: accumulate(iterable[, func, *, initial=None])
102 of two arguments. Elements of the input *iterable* may be any type
108 Usually, the number of elements output matches the input iterable.
111 has one more element than the input iterable.
115 def accumulate(iterable, func=operator.add, *, initial=None):
120 it = iter(iterable)
137 can be modeled by supplying the initial value in the iterable and using only
175 Make an iterator that returns elements from the first iterable until it is
176 exhausted, then proceeds to the next iterable, until all of the iterables are
187 .. classmethod:: chain.from_iterable(iterable)
190 single iterable argument that is evaluated lazily. Roughly equivalent to::
199 .. function:: combinations(iterable, r)
201 Return *r* length subsequences of elements from the input *iterable*.
204 the order of the input *iterable*. So, if the input *iterable* is sorted,
213 def combinations(iterable, r):
216 pool = tuple(iterable)
237 def combinations(iterable, r):
238 pool = tuple(iterable)
247 .. function:: combinations_with_replacement(iterable, r)
249 Return *r* length subsequences of elements from the input *iterable*
253 the order of the input *iterable*. So, if the input *iterable* is sorted,
262 def combinations_with_replacement(iterable, r):
264 pool = tuple(iterable)
283 def combinations_with_replacement(iterable, r):
284 pool = tuple(iterable)
330 .. function:: cycle(iterable)
332 Make an iterator returning elements from the iterable and saving a copy of each.
333 When the iterable is exhausted, return elements from the saved copy. Repeats
336 def cycle(iterable):
339 for element in iterable:
347 (depending on the length of the iterable).
350 .. function:: dropwhile(predicate, iterable)
352 Make an iterator that drops elements from the iterable as long as the predicate
357 def dropwhile(predicate, iterable):
359 iterable = iter(iterable)
360 for x in iterable:
364 for x in iterable:
367 .. function:: filterfalse(predicate, iterable)
369 Make an iterator that filters elements from iterable returning only those for
373 def filterfalse(predicate, iterable):
377 for x in iterable:
382 .. function:: groupby(iterable, key=None)
384 Make an iterator that returns consecutive keys and groups from the *iterable*.
387 the element unchanged. Generally, the iterable needs to already be sorted on
396 The returned group is itself an iterator that shares the underlying iterable
413 def __init__(self, iterable, key=None):
417 self.it = iter(iterable)
438 .. function:: islice(iterable, stop)
439 islice(iterable, start, stop[, step])
441 Make an iterator that returns selected elements from the iterable. If *start* is
442 non-zero, then elements from the iterable are skipped until start is reached.
451 def islice(iterable, *args):
462 # Consume *iterable* up to the *start* position.
463 for i, element in zip(range(start), iterable):
467 for i, element in enumerate(iterable):
473 for i, element in zip(range(i + 1, stop), iterable):
479 .. function:: pairwise(iterable)
481 Return successive overlapping pairs taken from the input *iterable*.
484 number of inputs. It will be empty if the input iterable has fewer than
489 def pairwise(iterable):
491 a, b = tee(iterable)
498 .. function:: permutations(iterable, r=None)
500 Return successive *r* length permutations of elements in the *iterable*.
503 of the *iterable* and all possible full-length permutations
507 the order of the input *iterable*. So, if the input *iterable* is sorted,
516 def permutations(iterable, r=None):
519 pool = tuple(iterable)
545 def permutations(iterable, r=None):
546 pool = tuple(iterable)
568 To compute the product of an iterable with itself, specify the number of
613 .. function:: starmap(function, iterable)
616 the iterable. Used instead of :func:`map` when argument parameters are already
617 grouped in tuples from a single iterable (the data has been "pre-zipped"). The
621 def starmap(function, iterable):
623 for args in iterable:
627 .. function:: takewhile(predicate, iterable)
629 Make an iterator that returns elements from the iterable as long as the
632 def takewhile(predicate, iterable):
634 for x in iterable:
641 .. function:: tee(iterable, n=2)
643 Return *n* independent iterators from a single iterable.
651 def tee(iterable, n=2):
652 it = iter(iterable)
666 Once :func:`tee` has made a split, the original *iterable* should not be
667 used anywhere else; otherwise, the *iterable* could get advanced without
672 call, even if the original *iterable* is threadsafe.
684 Iteration continues until the longest iterable is exhausted. Roughly equivalent to::
728 rather than bringing the whole iterable into memory all at once. Code volume is
736 def take(n, iterable):
737 "Return first n items of the iterable as a list"
738 return list(islice(iterable, n))
749 def tail(n, iterable):
752 return iter(collections.deque(iterable, maxlen=n))
764 def nth(iterable, n, default=None):
766 return next(islice(iterable, n, None), default)
768 def all_equal(iterable):
770 g = groupby(iterable)
773 def quantify(iterable, pred=bool):
775 return sum(map(pred, iterable))
777 def pad_none(iterable):
782 return chain(iterable, repeat(None))
784 def ncycles(iterable, n):
786 return chain.from_iterable(repeat(tuple(iterable), n))
816 def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
821 args = [iter(iterable)] * n
831 def triplewise(iterable):
832 "Return overlapping triplets from an iterable"
834 for (a, _), (b, c) in pairwise(pairwise(iterable)):
837 def sliding_window(iterable, n):
839 it = iter(iterable)
861 def partition(pred, iterable):
864 t1, t2 = tee(iterable)
902 def powerset(iterable):
904 s = list(iterable)
907 def unique_everseen(iterable, key=None):
914 for element in filterfalse(seen.__contains__, iterable):
918 for element in iterable:
924 def unique_justseen(iterable, key=None):
928 return map(next, map(operator.itemgetter(1), groupby(iterable, key)))
953 def first_true(iterable, default=False, pred=None):
954 """Returns the first true value in the iterable.
964 return next(filter(pred, iterable), default)
971 def random_permutation(iterable, r=None):
972 "Random selection from itertools.permutations(iterable, r)"
973 pool = tuple(iterable)
977 def random_combination(iterable, r):
978 "Random selection from itertools.combinations(iterable, r)"
979 pool = tuple(iterable)
984 def random_combination_with_replacement(iterable, r):
985 "Random selection from itertools.combinations_with_replacement(iterable, r)"
986 pool = tuple(iterable)
991 def nth_combination(iterable, r, index):
992 "Equivalent to list(combinations(iterable, r))[index]"
993 pool = tuple(iterable)