{
    "mode": "pydoc",
    "parameter": "itertools",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/itertools/json",
    "generated": "2026-06-02T15:03:23Z",
    "sections": {
        "NAME": {
            "content": "itertools - Functional tools for creating and using iterators.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Infinite iterators:",
            "subsections": [
                {
                    "name": "count",
                    "content": ""
                },
                {
                    "name": "cycle",
                    "content": ""
                },
                {
                    "name": "repeat",
                    "content": "Iterators terminating on the shortest input sequence:"
                },
                {
                    "name": "accumulate",
                    "content": ""
                },
                {
                    "name": "chain",
                    "content": "chain.fromiterable([p, q, ...]) --> p0, p1, ... plast, q0, q1, ..."
                },
                {
                    "name": "compress",
                    "content": ""
                },
                {
                    "name": "dropwhile",
                    "content": ""
                },
                {
                    "name": "groupby",
                    "content": ""
                },
                {
                    "name": "filterfalse",
                    "content": ""
                },
                {
                    "name": "islice",
                    "content": "seq[start:stop:step]"
                },
                {
                    "name": "pairwise",
                    "content": ""
                },
                {
                    "name": "starmap",
                    "content": ""
                },
                {
                    "name": "tee",
                    "content": ""
                },
                {
                    "name": "takewhile",
                    "content": ""
                },
                {
                    "name": "zip_longest",
                    "content": "Combinatoric generators:"
                },
                {
                    "name": "product",
                    "content": ""
                },
                {
                    "name": "permutations",
                    "content": ""
                },
                {
                    "name": "combinations",
                    "content": ""
                },
                {
                    "name": "combinations_with_replacement",
                    "content": ""
                }
            ]
        },
        "CLASSES": {
            "content": "builtins.object\naccumulate\nchain\ncombinations\ncombinationswithreplacement\ncompress\ncount\ncycle\ndropwhile\nfilterfalse\ngroupby\nislice\npairwise\npermutations\nproduct\nrepeat\nstarmap\ntakewhile\nziplongest\n",
            "subsections": [
                {
                    "name": "class accumulate",
                    "content": "|  accumulate(iterable, func=None, *, initial=None)\n|\n|  Return series of accumulated sums (or other binary function results).\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class chain",
                    "content": "|  chain(*iterables) --> chain object\n|\n|  Return a chain object whose .next() method returns elements from the\n|  first iterable until it is exhausted, then elements from the next\n|  iterable, until all of the iterables are exhausted.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  classgetitem(...) from builtins.type\n|      See PEP 585\n|\n|  fromiterable(iterable, /) from builtins.type\n|      Alternative chain() constructor taking a single iterable argument that evaluates lazily.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class combinations",
                    "content": "|  combinations(iterable, r)\n|\n|  Return successive r-length combinations of elements in the iterable.\n|\n|  combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  sizeof(...)\n|      Returns size in memory, in bytes.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class combinations_with_replacement",
                    "content": "|  combinationswithreplacement(iterable, r)\n|\n|  Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.\n|\n|  combinationswithreplacement('ABC', 2) --> ('A','A'), ('A','B'), ('A','C'), ('B','B'), ('B','C'), ('C','C')\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  sizeof(...)\n|      Returns size in memory, in bytes.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class compress",
                    "content": "|  compress(data, selectors)\n|\n|  Return data elements corresponding to true selector elements.\n|\n|  Forms a shorter iterator from selected data elements using the selectors to\n|  choose the data elements.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class count",
                    "content": "|  count(start=0, step=1)\n|\n|  Return a count object whose .next() method returns consecutive values.\n|\n|  Equivalent to:\n|      def count(firstval=0, step=1):\n|          x = firstval\n|          while 1:\n|              yield x\n|              x += step\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class cycle",
                    "content": "|  cycle(iterable, /)\n|\n|  Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class dropwhile",
                    "content": "|  dropwhile(predicate, iterable, /)\n|\n|  Drop items from the iterable while predicate(item) is true.\n|\n|  Afterwards, return every element until the iterable is exhausted.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class filterfalse",
                    "content": "|  filterfalse(function, iterable, /)\n|\n|  Return those items of iterable for which function(item) is false.\n|\n|  If function is None, return the items that are false.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class groupby",
                    "content": "|  groupby(iterable, key=None)\n|\n|  make an iterator that returns consecutive keys and groups from the iterable\n|\n|  iterable\n|    Elements to divide into groups according to the key function.\n|  key\n|    A function for computing the group category for each element.\n|    If the key function is not specified or is None, the element itself\n|    is used for grouping.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class islice",
                    "content": "|  islice(iterable, stop) --> islice object\n|  islice(iterable, start, stop[, step]) --> islice object\n|\n|  Return an iterator whose next() method returns selected values from an\n|  iterable.  If start is specified, will skip all preceding elements;\n|  otherwise, start defaults to zero.  Step defaults to one.  If\n|  specified as another value, step determines how many values are\n|  skipped between successive calls.  Works like a slice() on a list\n|  but returns an iterator.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class pairwise",
                    "content": "|  pairwise(iterable, /)\n|\n|  Return an iterator of overlapping pairs taken from the input iterator.\n|\n|  s -> (s0,s1), (s1,s2), (s2, s3), ...\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class permutations",
                    "content": "|  permutations(iterable, r=None)\n|\n|  Return successive r-length permutations of elements in the iterable.\n|\n|  permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  sizeof(...)\n|      Returns size in memory, in bytes.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class product",
                    "content": "|  product(*iterables, repeat=1) --> product object\n|\n|  Cartesian product of input iterables.  Equivalent to nested for-loops.\n|\n|  For example, product(A, B) returns the same as:  ((x,y) for x in A for y in B).\n|  The leftmost iterators are in the outermost for-loop, so the output tuples\n|  cycle in a manner similar to an odometer (with the rightmost element changing\n|  on every iteration).\n|\n|  To compute the product of an iterable with itself, specify the number\n|  of repetitions with the optional repeat keyword argument. For example,\n|  product(A, repeat=4) means the same as product(A, A, A, A).\n|\n|  product('ab', range(3)) --> ('a',0) ('a',1) ('a',2) ('b',0) ('b',1) ('b',2)\n|  product((0,1), (0,1), (0,1)) --> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ...\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  sizeof(...)\n|      Returns size in memory, in bytes.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class repeat",
                    "content": "|  repeat(object [,times]) -> create an iterator which returns the object\n|  for the specified number of times.  If not specified, returns the object\n|  endlessly.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  lengthhint(...)\n|      Private method returning an estimate of len(list(it)).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class starmap",
                    "content": "|  starmap(function, iterable, /)\n|\n|  Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class takewhile",
                    "content": "|  takewhile(predicate, iterable, /)\n|\n|  Return successive entries from an iterable as long as the predicate evaluates to true for each entry.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                },
                {
                    "name": "class zip_longest",
                    "content": "|  ziplongest(iter1 [,iter2 [...]], [fillvalue=None]) --> ziplongest object\n|\n|  Return a ziplongest object whose .next() method returns a tuple where\n|  the i-th element comes from the i-th iterable argument.  The .next()\n|  method continues until the longest iterable in the argument sequence\n|  is exhausted and then it raises StopIteration.  When the shorter iterables\n|  are exhausted, the fillvalue is substituted in their place.  The fillvalue\n|  defaults to None or can be specified by a keyword argument.\n|\n|  Methods defined here:\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  next(self, /)\n|      Implement next(self).\n|\n|  reduce(...)\n|      Return state information for pickling.\n|\n|  setstate(...)\n|      Set state information for unpickling.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "tee",
                    "content": "Returns a tuple of n independent iterators.\n"
                }
            ]
        },
        "FILE": {
            "content": "(built-in)\n\n",
            "subsections": []
        }
    },
    "summary": "itertools - Functional tools for creating and using iterators.",
    "flags": [],
    "examples": [],
    "see_also": []
}