Alternative way to iterate in batches on a dataset

We iterate on batches with the following code:

for batch in iterator:

where the iterator has been instantiated with the following code

train_iterator, valid_iterator, test_iterator = data.BucketIterator.splits(
    (train_data, valid_data, test_data),
    batch_size = BATCH_SIZE,
    device = device)

What I want to do is something like the following:

batch = next(iterator)

But this obviously does not work. The reason that I want such a think is that I want to iterate in two datasets (multitask learning) and so I want to have two iterators (one for each dataset), and be able to alternate between them.

Can you help me on that?

OK, I did the following:

batches = iter(iterator)    # <---before the loop

and then inside the loop, I can iterate in batches:

batch = next(batches)