Ask Your Question
1

List of variables as function arguments

asked 4 years ago

ube gravatar image

I would like to define a function that takes a long list of variables as input and some complicated expression of my variables as my output, but I just don't seem to be able to make it work.

Something along the line of:

var('x_1,x_2,x_3')
long_list_of_variables = [x_1, x_2,x_3]
complicated_expression=(x_1^2+x_2^2-x_3)^2
f(tuple(long_list_of_variables))=complicated_expression

But with much more variables.

I've tried different variations of this but I always seem to end up with the 'can't assign to function call'-error. Are there any way to achieve what I'm trying to do?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

Juanjo gravatar image

Just replace the last line of your code by

f = complicated_expression.function(*long_list_of_variables)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 4 years ago

Seen: 551 times

Last updated: Jun 28 '20