reusing generators

K

kmdaily

Hello, I have a two large files that I need to read in records from
and compare in a pairwise fashion: Memory is an issue, so I want to
use a generator to get each record one at a time. However, doing the
comparisons with nested for loops, the inner generator will run out of
items. How can I restart the generator from the beginning of the file
each time through the outer loop? Thanks!
 
P

Paul Rubin

Hello, I have a two large files that I need to read in records from
and compare in a pairwise fashion: Memory is an issue, so I want to
use a generator to get each record one at a time. However, doing the
comparisons with nested for loops, the inner generator will run out of
items. How can I restart the generator from the beginning of the file
each time through the outer loop? Thanks!

If the files are that large, maybe you want to rethink that quadratic
algorithm. But if you really want to restart the generator, the
simplest way is just close and re-open the file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,353
Latest member
RogerDoger

Latest Threads

Top