It is impossible to know how many values ββthe iterator will produce without waiting until the end. Note that the iterator can also be infinite, so in this case the total number is not even defined.
If you can guarantee that the iterator will be finite, one way to do what you ask is to convert it to a list (using list(iterator) ) and then use the usual list functions ( len , slicing) to split it into half. Of course, in this way all the elements will be in memory at the same time, which may or may not be acceptable in your case.
Alternatively, you can try using a custom iterator class that keeps track of the total number of items to be released. No matter how possible it depends on how exactly these iterators are obtained.
source share