iterator

An object that produces the items of a sequence one at a time, on request, instead of all at once.

In more detail

A for loop works by asking an iterator for its next item until it is exhausted. Iterators let programs process huge files or endless streams one value at a time without loading everything. Anything that can hand out an iterator, such as a list or a file, is called an iterable.

Example

heapq.merge reads one value at a time from each sorted input.

Related terms

Taught in

References

Certification courses