Iterator function with ITER

Iterator is access to the collection element, a next () method of the object, rather than by counting index.
Several G of data, the use of iterators, memory usage significantly reduced, this is the biggest advantage of iterators.
 
List, etc. are strings can be iterative, loop can be traversed, but to become an iterator ITER by function, will be achieved for / while loop traversal the like.
Example:
>>>i=iter('asdfg')
>>>next(i)
'a'
>>>next(i)
's'
>>>list(i)
['d','f','g']
 
 
itertools is very efficient to create the iterator's python module provided to be introduced from the conventional method.
Example:
>>>from itertools import chain
>>>i=chain('AA','BB')
>>>list(i)
['A','A','B','B']
 
 
Learning Reference:
https://blog.csdn.net/weixin_44020598/article/details/85217727
http://baijiahao.baidu.com/s?id=1605521786183411929&wfr=spider&for=pc
 
 

Guess you like

Origin www.cnblogs.com/myshuzhimei/p/11747727.html