I have to return many variables from my function:
a = 5
b = 6
c = 8
d = 6
...
return a,b,c,d,e,f,g,h
Problem is that I would like to do it through array to save a code lines:
for (...):
ar[x] = ... # For x = a,b,c,d,e, ...
But I have to return variables in format 'return a,b,c,d,e' and I do not want to write it as:
return ar[a], ar[b], ar[c], ...
So can I use a generator for it and how? Somethig like:
return item for item in len(ar)
When you are "returning multiple variables", you are actually just returning a tuple. You can do this:
return tuple(ar)
or even
return ar
Assuming, of course, that your array contains everything you want to return in the correct order, and only that.
It would be nice to see more code, but it is likely that if you can fill that list using a loop, then it's semantically a single value (a homogenous collection) anyway.