• Home
  • Raw
  • Download

Lines Matching +full:repeat +full:- +full:element

2 :mod:`itertools` --- Functions creating iterators for efficient looping
30 These tools and their built-in counterparts also work well with the high-speed
32 operator can be mapped across two vectors to form an efficient dot-product:
41 …tart, start+step, start+2*step, ... ``count(10) --> 10 11 12 13 14 ...``
42 …1, ... plast, p0, p1, ... ``cycle('ABCD') --> A B C D A B C D ...…
43 :func:`repeat` elem [,n] elem, elem, elem, ... endlessly or up to n times …
51 … p0, p1, ... plast, q0, q1, ... ``chain('ABC', 'DEF') --> A B C D E F``
52 …[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F``
53 …n], seq[n+1], starting when pred fails ``dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1``
54 :func:`groupby` iterable[, keyfunc] sub-iterators grouped by value of keyfunc(v)
55 …ents of seq where pred(elem) is true ``ifilter(lambda x: x%2, range(10)) --> 1 3 5 7 9``
56 …of seq where pred(elem) is false ``ifilterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8``
57 … elements from seq[start:stop:step] ``islice('ABCDEFG', 2, None) --> C D E F G``
58 … func(p0, q0), func(p1, q1), ... ``imap(pow, (2,3,10), (5,2,3)) --> 32 9 1000``
59 …seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000``
61 …q[0], seq[1], until pred fails ``takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4``
62 … (p[0], q[0]), (p[1], q[1]), ... ``izip('ABCD', 'xy') --> Ax By``
63 …(p[1], q[1]), ... ``izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-``
71 … p, q, ... [repeat=1] cartesian product, equivalent to a ne…
72 :func:`permutations` p[, r] r-length tuples, all po…
73 :func:`combinations` p, r r-length tuples, in sor…
74 :func:`combinations_with_replacement` p, r r-length tuples, in sor…
75 ``product('ABCD', repeat=2)`` ``AA AB AC AD BA BB BC …
82 .. _itertools-functions:
85 ------------------
100 # chain('ABC', 'DEF') --> A B C D E F
102 for element in it:
103 yield element
112 # chain.from_iterable(['ABC', 'DEF']) --> A B C D E F
114 for element in it:
115 yield element
129 value. So if the input elements are unique, there will be no repeat
135 # combinations('ABCD', 2) --> AB AC AD BC BD CD
136 # combinations(range(4), 3) --> 012 013 023 123
145 if indices[i] != i + n - r:
151 indices[j] = indices[j-1] + 1
165 The number of items returned is ``n! / r! / (n-r)!`` when ``0 <= r <= n``
186 # combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC
195 if indices[i] != n - 1:
199 indices[i:] = [indices[i] + 1] * (r - i)
209 for indices in product(range(n), repeat=r):
213 The number of items returned is ``(n+r-1)! / r! / (n-1)!`` when ``n > 0``.
220 have a corresponding element in *selectors* that evaluates to ``True``.
225 # compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
238 # count(10) --> 10 11 12 13 14 ...
239 # count(2.5, 0.5) -> 2.5 3.0 3.5 ...
250 added *step* argument and allowed non-integer arguments.
259 # cycle('ABCD') --> A B C D A B C D A B C D ...
261 for element in iterable:
262 yield element
263 saved.append(element)
265 for element in saved:
266 yield element
275 is true; afterwards, returns every element. Note, the iterator does not produce
277 start-up time. Roughly equivalent to::
280 # dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1
293 The *key* is a function computing a key value for each element. If not
295 the element unchanged. Generally, the iterable needs to already be sorted on
319 # [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
320 # [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
351 # ifilter(lambda x: x%2, range(10)) --> 1 3 5 7 9
366 # ifilterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
385 # imap(pow, (2,3,10), (5,2,3)) --> 32 9 1000
399 non-zero, then elements from the iterable are skipped until start is reached.
406 multi-line report may list a name field on every third line). Roughly equivalent to::
409 # islice('ABCDEFG', 2) --> A B
410 # islice('ABCDEFG', 2, 4) --> C D
411 # islice('ABCDEFG', 2, None) --> C D E F G
412 # islice('ABCDEFG', 0, None, 2) --> A C E G
420 for i, element in izip(xrange(start), iterable):
424 for i, element in enumerate(iterable):
426 yield element
430 for i, element in izip(xrange(i + 1, stop), iterable):
444 lock-step iteration over several iterables at a time. Roughly equivalent to::
447 # izip('ABCD', 'xy') --> Ax By
456 The left-to-right evaluation order of the iterables is guaranteed. This
457 makes possible an idiom for clustering a data series into n-length groups
468 iterables are of uneven length, missing values are filled-in with *fillvalue*.
475 # izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
477 counter = [len(args) - 1]
481 counter[0] -= 1
483 fillers = repeat(fillvalue)
503 of the *iterable* and all possible full-length permutations
511 value. So if the input elements are unique, there will be no repeat
517 # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
518 # permutations(range(3)) --> 012 021 102 120 201 210
525 cycles = range(n, n-r, -1)
529 cycles[i] -= 1
532 cycles[i] = n - i
535 indices[i], indices[-j] = indices[-j], indices[i]
549 for indices in product(range(n), repeat=r):
553 The number of items returned is ``n! / (n-r)!`` when ``0 <= r <= n``
558 .. function:: product(*iterables[, repeat])
562 Roughly equivalent to nested for-loops in a generator expression. For example,
565 The nested loops cycle like an odometer with the rightmost element advancing
571 repetitions with the optional *repeat* keyword argument. For example,
572 ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``.
578 # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
579 # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
580 pools = map(tuple, args) * kwds.get('repeat', 1)
589 .. function:: repeat(object[, times])
596 def repeat(object, times=None):
597 # repeat(10, 3) --> 10 10 10
605 A common use for *repeat* is to supply a stream of constant values to *imap*
608 >>> list(imap(pow, xrange(10), repeat(2)))
615 grouped in tuples from a single iterable (the data has been "pre-zipped"). The
620 # starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000
634 # takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4
670 .. _itertools-recipes:
673 -------
683 "vectorized" building blocks over the use of for-loops and :term:`generator`\s
697 "Advance the iterator n-steps ahead. If n is None, consume entirely."
700 # feed the entire iterator into a zero-length deque
722 Useful for emulating the behavior of the built-in map() function.
724 return chain(iterable, repeat(None))
728 return chain.from_iterable(repeat(tuple(iterable), n))
738 """Repeat calls to func with specified arguments.
743 return starmap(func, repeat(args))
744 return starmap(func, repeat(args, times))
747 "s -> (s0,s1), (s1,s2), (s2, s3), ..."
753 "Collect data into fixed-length chunks or blocks"
754 # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
759 "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
768 pending -= 1
772 "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
778 # unique_everseen('AAAABBBCCDAABBB') --> A B C D
779 # unique_everseen('ABBCcAD', str.lower) --> A B C D
783 for element in ifilterfalse(seen.__contains__, iterable):
784 seen_add(element)
785 yield element
787 for element in iterable:
788 k = key(element)
791 yield element
794 "List unique elements, preserving order. Remember only the element just seen."
795 # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
796 # unique_justseen('ABBCcAD', str.lower) --> A B C A D
802 Converts a call-until-exception interface to an iterator interface.
825 pools = map(tuple, args) * kwds.get('repeat', 1)
849 """Inspect the i-th upcomping value from a tee object