Python 3.4.2 (default, Oct 8 2014, 13:44:52)
[GCC 4.9.1 20140903 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> gen = (x for x in range(10)) ## Need to wrap range into ()'s to create a generator, next(range(10)) is invalid
>>> list(zip(gen, [1,2,3])) ## zip will "eat up" the number 3
[(0, 1), (1, 2), (2, 3)]
>>> next(gen) ## Here i need next to return 3
4
>>>
The problem is that I'm losing a value after the zip call. This would be a bigger issue had it not been for the fact that gen is pure code.
I don't know whether or not it would be possible to create a function that behaves like this, it's definitely possible if only one of the arguments to the zip function is a generator and the rest are "normal" iterators where all the values are known, and stored in memory. If that were the case you could just check the generator last.
Basically what I am wondering is if there is any function in the python standard library that will act like I need it to in this case.
Of course, in some cases one could just do something like
xs = list(gen)
Then you only have to deal with a list.
I could also add, that getting the last value that zip got from gen would also be a solution to this problem.