Iterator Objects

Python provides two general-purpose iterator objects. The first, a sequenceiterator, works with an arbitrary sequence supporting the__getitem__()method. The second works with a callable object and a sentinel value, callingthe callable for each item in the sequence, and ending the iteration when thesentinel value is returned.

PyTypeObjectPySeqIter_Type
Part of theStable ABI.

Type object for iterator objects returned byPySeqIter_New() and theone-argument form of theiter() built-in function for built-in sequencetypes.

intPySeqIter_Check(PyObject*op)

Return true if the type ofop isPySeqIter_Type. This functionalways succeeds.

PyObject*PySeqIter_New(PyObject*seq)
Return value: New reference. Part of theStable ABI.

Return an iterator that works with a general sequence object,seq. Theiteration ends when the sequence raisesIndexError for the subscriptingoperation.

PyTypeObjectPyCallIter_Type
Part of theStable ABI.

Type object for iterator objects returned byPyCallIter_New() and thetwo-argument form of theiter() built-in function.

intPyCallIter_Check(PyObject*op)

Return true if the type ofop isPyCallIter_Type. Thisfunction always succeeds.

PyObject*PyCallIter_New(PyObject*callable,PyObject*sentinel)
Return value: New reference. Part of theStable ABI.

Return a new iterator. The first parameter,callable, can be any Pythoncallable object that can be called with no parameters; each call to it shouldreturn the next item in the iteration. Whencallable returns a value equal tosentinel, the iteration will be terminated.