阅读背景:

Python:获取生成器中的项目数而不存储项目

来源:互联网 

I have a generator for a large set of items. I want to iterate through them once, outputting them to a file. However, with the file format I currently have, I first have to output the number of items I have. I don't want to build a list of the items in memory, as there are too many of them and that would take a lot of time and memory. Is there a way to iterate through the generator, getting its length, but somehow be able to iterate through it again later, getting the same items?I have a generator for a large set of items. I




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: