在 英语 中使用 An iterator 的示例及其翻译为 中文
{-}
-
Political
-
Ecclesiastic
-
Programming
This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been consumed.
We have shown that you can create an iterator by calling iter, into_iter, or iter_mut on a vector.
Plain objects can't normally be iterated over, unless you have defined an iterator for it.
In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time.
In the statement for X in Y, Y must be an iterator or some object for which iter() can create an iterator.
Generators are a Python core language construct that allow a function's return value to behave as an iterator.
Let's talk about consumers first, since you have already seen an iterator.
In the Range object, there are minimum and maximum values, while in Seq we see an iterator.
Sequence unpacking also supports iterators: if you know an iterator will return N elements, you can unpack them into an N-tuple.
Note that it's not possible to use an iterator of promises to achieve the same result.
Two common operations on an iterator's output are 1 performing some operation for every element, 2 selecting a subset of elements that meet some condition.
An iterator is an object with a next(Python 2) or__next__(Python 3) method.
However, when you request an iterator from an iterator(which you would rarely do), it just gives you a copy of itself.
Its results are an iterator function, a state, and an initial value for the first iterator variable.
One of the easiest ways to create an iterator is to use the range notation a… b.
Once we have created an iterator, we can choose to use it in a variety of ways.
According to Wikipedia, an iterator is an object that enables a programmer to traverse a container, particularly lists.
For example, consider the following code, which uses an iterator to walk the keys of a hash in Java.
Once created, an iterator object can be iterated explicitly by repeatedly calling next().
Either way, an iterator is created, i.e. some object that can give you the data you want.