Lines Matching refs:iterable
54 :func:`groupby` iterable[, keyfunc] sub-iterators grouped by value of keyfunc(v)
94 Make an iterator that returns elements from the first iterable until it is
95 exhausted, then proceeds to the next iterable, until all of the iterables are
106 .. classmethod:: chain.from_iterable(iterable)
109 single iterable argument that is evaluated lazily. Roughly equivalent to::
120 .. function:: combinations(iterable, r)
122 Return *r* length subsequences of elements from the input *iterable*.
125 input *iterable* is sorted, the combination tuples will be produced
134 def combinations(iterable, r):
137 pool = tuple(iterable)
158 def combinations(iterable, r):
159 pool = tuple(iterable)
170 .. function:: combinations_with_replacement(iterable, r)
172 Return *r* length subsequences of elements from the input *iterable*
176 input *iterable* is sorted, the combination tuples will be produced
185 def combinations_with_replacement(iterable, r):
187 pool = tuple(iterable)
206 def combinations_with_replacement(iterable, r):
207 pool = tuple(iterable)
252 .. function:: cycle(iterable)
254 Make an iterator returning elements from the iterable and saving a copy of each.
255 When the iterable is exhausted, return elements from the saved copy. Repeats
258 def cycle(iterable):
261 for element in iterable:
269 (depending on the length of the iterable).
272 .. function:: dropwhile(predicate, iterable)
274 Make an iterator that drops elements from the iterable as long as the predicate
279 def dropwhile(predicate, iterable):
281 iterable = iter(iterable)
282 for x in iterable:
286 for x in iterable:
290 .. function:: groupby(iterable[, key])
292 Make an iterator that returns consecutive keys and groups from the *iterable*.
295 the element unchanged. Generally, the iterable needs to already be sorted on
304 The returned group is itself an iterator that shares the underlying iterable
321 def __init__(self, iterable, key=None):
325 self.it = iter(iterable)
344 .. function:: ifilter(predicate, iterable)
346 Make an iterator that filters elements from iterable returning only those for
350 def ifilter(predicate, iterable):
354 for x in iterable:
359 .. function:: ifilterfalse(predicate, iterable)
361 Make an iterator that filters elements from iterable returning only those for
365 def ifilterfalse(predicate, iterable):
369 for x in iterable:
378 arguments as a tuple. Like :func:`map` but stops when the shortest iterable is
395 .. function:: islice(iterable, stop)
396 islice(iterable, start, stop[, step])
398 Make an iterator that returns selected elements from the iterable. If *start* is
399 non-zero, then elements from the iterable are skipped until start is reached.
408 def islice(iterable, *args):
419 # Consume *iterable* up to the *start* position.
420 for i, element in izip(xrange(start), iterable):
424 for i, element in enumerate(iterable):
430 for i, element in izip(xrange(i + 1, stop), iterable):
469 Iteration continues until the longest iterable is exhausted. Roughly equivalent to::
498 .. function:: permutations(iterable[, r])
500 Return successive *r* length permutations of elements in the *iterable*.
503 of the *iterable* and all possible full-length permutations
507 input *iterable* is sorted, the permutation tuples will be produced
516 def permutations(iterable, r=None):
519 pool = tuple(iterable)
545 def permutations(iterable, r=None):
546 pool = tuple(iterable)
570 To compute the product of an iterable with itself, specify the number of
611 .. function:: starmap(function, iterable)
614 the iterable. Used instead of :func:`imap` when argument parameters are already
615 grouped in tuples from a single iterable (the data has been "pre-zipped"). The
619 def starmap(function, iterable):
621 for args in iterable:
626 Now, any iterable is allowed.
628 .. function:: takewhile(predicate, iterable)
630 Make an iterator that returns elements from the iterable as long as the
633 def takewhile(predicate, iterable):
635 for x in iterable:
642 .. function:: tee(iterable[, n=2])
644 Return *n* independent iterators from a single iterable. Roughly equivalent to::
646 def tee(iterable, n=2):
647 it = iter(iterable)
658 Once :func:`tee` has made a split, the original *iterable* should not be
659 used anywhere else; otherwise, the *iterable* could get advanced without
680 rather than bringing the whole iterable into memory all at once. Code volume is
688 def take(n, iterable):
689 "Return first n items of the iterable as a list"
690 return list(islice(iterable, n))
706 def nth(iterable, n, default=None):
708 return next(islice(iterable, n, None), default)
710 def all_equal(iterable):
712 g = groupby(iterable)
715 def quantify(iterable, pred=bool):
717 return sum(imap(pred, iterable))
719 def padnone(iterable):
724 return chain(iterable, repeat(None))
726 def ncycles(iterable, n):
728 return chain.from_iterable(repeat(tuple(iterable), n))
746 def pairwise(iterable):
748 a, b = tee(iterable)
752 def grouper(iterable, n, fillvalue=None):
755 args = [iter(iterable)] * n
771 def powerset(iterable):
773 s = list(iterable)
776 def unique_everseen(iterable, key=None):
783 for element in ifilterfalse(seen.__contains__, iterable):
787 for element in iterable:
793 def unique_justseen(iterable, key=None):
797 return imap(next, imap(itemgetter(1), groupby(iterable, key)))
828 def random_permutation(iterable, r=None):
829 "Random selection from itertools.permutations(iterable, r)"
830 pool = tuple(iterable)
834 def random_combination(iterable, r):
835 "Random selection from itertools.combinations(iterable, r)"
836 pool = tuple(iterable)
841 def random_combination_with_replacement(iterable, r):
842 "Random selection from itertools.combinations_with_replacement(iterable, r)"
843 pool = tuple(iterable)