Consumer操作一个迭代器 ,返回某些类型的值。 A consumer operates on an iterator , returning some kind of value or values.Consumers operate on an iterator , producing some final set of values. 做到这一点最简单的方法是采用一个迭代器 ,它是一个对象,实现了Iterator接口或ListIterator接口。 The easiest way to do this is to employ an iterator , which is an object that implements either the Iterator or the ListIterator interface. TcpListener的incoming方法返回一个迭代器 ,它提供了一系列的流(更准确的说是TcpStream类型的流)。 The incoming method on TcpListener returns an iterator that gives us a sequence of streams(more specifically, streams of type TcpStream). 让我们来看看一个迭代器 实现在实践中看起来是什么样的。 Let's see what an iterator implementation looks like in practice. Combinations with other parts of speech
做到这一点最简单的方法是采用一个迭代器 ,它是一个对象,实现了Iterator接口或ListIterator接口。 The better way is to employ an iterator , which is an object that implements either the Iterator or the ListIterator interface. 同样的,如果你只是想要获取一个迭代器 ,你可以使用语法几乎相通的生成器表达式。 Similarly, if you wish to get a iterator only, you can use Generator Expression with almost the same syntax. 这里,我们创建了一个迭代器 ,使用了两个适配器,接着消费了其值。 Here, we're creating an iterator , using two adaptors, and then consuming the value. 举个例子,list对象是一个可迭代对象,但并不是一个迭代器 (它实现了__iter__但并未实现next)。 For example, the list object is an iterable but not an iterator (it implements__iter__ but not next). 做到这一点最简单的方法是采用一个迭代器 ,它是一个对象,实现了Iterator接口或ListIterator接口。 By far, the easiest way to do this is to employ an iterator , an object that implements either the Iterator or the Listiterator interface. 此函数返回一个迭代器 ,它将从缓冲区读取大小相同的块,直到其所有内容都被处理。 This function returns an iterator which will read equally-sized chunks from the buffer until all its contents have been consumed. 我们已经展示了可以通过在vector上调用iter、into_iter或iter_mut来创建一个迭代器 。 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. Python2中,文件对象有一个xreadlines()方法,返回一个迭代器 ,一次读取文件的一行。 In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time. 在表达式forXinY,Y要么自身是一个迭代器 ,要么能够由iter()创建一个迭代器 。 In the statement for X in Y, Y must be an iterator or some object for which iter() can create an iterator . 首先让我们来谈谈消费者,因为你已经看到一个迭代器 。 Let's talk about consumers first, since you have already seen an iterator . 在Range对象中,有最小值和最大值,而在Seq中我们看到一个迭代器 。 In the Range object, there are minimum and maximum values, while in Seq we see an iterator . 这是因为,for循环需要一个迭代器 ,并使用next()函数进行迭代。 This is because, a forloop takes an iterator and iterates over it using next() function. 迭代一个迭代器 被称为消耗了这个迭代器,因为它通常只能执行一次。 Iterating over an iterator is said to consume the iterator, because it is generally only possible to do once. 在主线程中,不再显式调用recv函数:而是将rx当作一个迭代器 。 In the main thread, we're not calling the recv function explicitly anymore: instead, we're treating rx as an iterator . 生成器是Python的一个核心语言构件,它能使函数的返回值表现为一个迭代器 。 Generators are a Python core language construct that allow a function's return value to behave as an iterator . 作为顺序的查找,set::find将会返回一个迭代器 ,要么指向找到的元素,要么指向'end()'。 As‘ordinal' find, set::find will return an iterator , either to the element found, or to‘end()'. 作为‘顺序的'find函数,set::find会返回一个迭代器 ,不论这个迭代器指向被找到的元素,还是指向‘end()'。 As‘ordinal' find, set::find will return an iterator , either to the element found, or to‘end()'. 从技术上来说,range()函数返回的既不是列表也不是元组,而是一个迭代器 ,但稍后您将学到它们的区别。 (Technically, the range() function returns an iterator , not a list or a tuple, but you will learn about that distinction later.). 在语句forXinY中,Y必须是一个迭代器 或者是一个拥有iter()方法的对象,这个方法可以为其创造一个迭代器 。 In the statement for X in Y, Y must be an iterator or some object for which iter() can create an iterator . Groupby(names,len)将会将所有的4个字母的名字放在一个迭代器 里面,所有的5个字母的名字放在另一个迭代器 里,以此类推。 Groupby(names, len) will put all the 4-letter names in one iterator , all the 5-letter names in another iterator , and so on. Then remember that a generator is an iterator ; Then remember that a generator is an iterator ; An iterator is an object with a next method.创建一个迭代器 ,返回iterable中所有元素并保存一个副本。 Make an iterator returning elements from the iterable and saving a copy of each.
Display more examples
Results: 133 ,
Time: 0.0175