~ubuntu-branches/ubuntu/saucy/python2.7/saucy-proposed

« back to all changes in this revision

Viewing changes to Doc/library/itertools.rst

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-05-15 19:15:16 UTC
  • mto: (36.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: package-import@ubuntu.com-20130515191516-zmv6to904wemey7s
Tags: upstream-2.7.5
ImportĀ upstreamĀ versionĀ 2.7.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
732
732
       next(b, None)
733
733
       return izip(a, b)
734
734
 
735
 
   def grouper(n, iterable, fillvalue=None):
 
735
   def grouper(iterable, n, fillvalue=None):
736
736
       "Collect data into fixed-length chunks or blocks"
737
 
       # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
 
737
       # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
738
738
       args = [iter(iterable)] * n
739
739
       return izip_longest(fillvalue=fillvalue, *args)
740
740
 
828
828
       indices = sorted(random.randrange(n) for i in xrange(r))
829
829
       return tuple(pool[i] for i in indices)
830
830
 
 
831
   def tee_lookahead(t, i):
 
832
       """Inspect the i-th upcomping value from a tee object
 
833
          while leaving the tee object at its current position.
 
834
 
 
835
          Raise an IndexError if the underlying iterator doesn't
 
836
          have enough values.
 
837
 
 
838
       """
 
839
       for value in islice(t.__copy__(), i, None):
 
840
           return value
 
841
       raise IndexError(i)
 
842
 
831
843
Note, many of the above recipes can be optimized by replacing global lookups
832
844
with local variables defined as default values.  For example, the
833
845
*dotproduct* recipe can be written as::