So, consider the following:
iterable1 = (foo.value for foo in foos)
iterable2 = (bar.value(foo) for foo in foos)
Since both iterables are creates from same list.. I was wondering if I can generate them together..
like
compounded_iter = ( (foo.value,bar.value(foo)) for foo in foos)
The above works..
But is it possible to get something like:
iter1, iter2 = (......) but in one shot?
I am not able to figure that out..
compounded_iter = ( (foo.value,bar.value(foo)) for foo in foos)
iter1,iter2 = zip(*compounded_iter)
You can, of course, combine those into one line.
compounded_iter = ( (foo.value,bar.value(foo)) for foo in foos)
iter1,iter2 = [x[0] for x in compound_iter],[x[1] for x in compound_iter]
this would put all the values in iter1, and all the bar.values in iter2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With