How to make the "number of returns" a variable

Viewed 76

Lets consider a normal function:

def function(stuff):
    return result

To call it and get the result in a variable:

variable = function(stuff)

I can do the same with 3 (for example) results:

def function(stuff):
    return result1, result2, result3

To call it and get the results in 3 variables:

variable1, variable2, variable3 = function(stuff)

My question is: How can I write a function that automatically reads and changes when I set a variable called "number of results". Or, in my real case, the "number of results" will depend on the length of my variable stuff (the variable stuff is a list of arrays).

I hope this question was not answered before.

2 Answers
Related