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.
- PyTypeObject
PySeqIter_Type¶ Type object for iterator objects returned by
PySeqIter_New()and theone-argument form of theiter()built-in function for built-in sequencetypes.
- int
PySeqIter_Check(op)¶ Return true if the type ofop is
PySeqIter_Type.
- PyObject*
PySeqIter_New(PyObject *seq)¶ - Return value: New reference.
Return an iterator that works with a general sequence object,seq. Theiteration ends when the sequence raises
IndexErrorfor the subscriptingoperation.
- PyTypeObject
PyCallIter_Type¶ Type object for iterator objects returned by
PyCallIter_New()and thetwo-argument form of theiter()built-in function.
- int
PyCallIter_Check(op)¶ Return true if the type ofop is
PyCallIter_Type.
- PyObject*
PyCallIter_New(PyObject *callable,PyObject *sentinel)¶ - Return value: New reference.
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.