Ask Your Question
1

List of variables as function arguments

asked 2020-06-25 13:03:48 +0100

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-06-28 03:18:15 +0100

Juanjo gravatar image

Just replace the last line of your code by

f = complicated_expression.function(*long_list_of_variables)
edit flag offensive delete link more

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: 2020-06-25 13:03:48 +0100

Seen: 469 times

Last updated: Jun 28 '20