Reputation: 340
fun(x)
is function that returns 3 values ret1, ret2, ret3
I have this code example which shows me how to get the returns of 5 function calls sorted in to separate tuples of the returns :
ret1, ret2, ret3 = zip(fun(0), fun(1), fun(2), fun(3), fun(4))
I want to do this now for n function calls without explicitly stating the function call, like with
[fun(x) for x in range(5)]
I guess my problem is that I'm no expert of the zip functionality so help would be appreciated.
Upvotes: 1
Views: 56
Reputation: 1824
It sounds like you're trying to unpack that list comprehension to pass it to the zip function. This is how you do that (e.g. for 10 functions)
ret1, ret2, ret3 = zip(*(fun(x) for x in range(10)))
Upvotes: 3