0

I have a python function which takes as input an arbitrary number of parameters. I beleive this is implemented via *args (thanks @Anurag Wagh for pointing this out). I would like to be able to pass to it a list of values. Here is the specific code I have:

from sympy import solve_poly_system, symbols
x,y,z = symbols('x y z')
print(solve_poly_system([y**2 - x**3 + 1, y*x], x, y))

Instead of passing x and y to solve_poly_system, I want to be able to pass it a list L something like so:

print(solve_poly_system([y**2 - x**3 + 1, y*x], L))

where L = [x,y].

Is this possible? Please note, although I am interested in the specific case of the solve_poly_system function, I am more broadly interested in the passing a list to any function in python that takes an arbitrary number of inputs.

To put this another way, I want to know how to pass a list of values to a function which takes *args as input. In particular I am interested in the case where the length of the list is not known until run time and may change during run time.

2
  • I think you are looking for *args type function. geeksforgeeks.org/args-kwargs-python Commented Oct 21, 2020 at 5:12
  • Thanks. This is what I am talking about, however the post you link to doesn't answer my question. I will edit my question shortly to reflect this. Commented Oct 21, 2020 at 5:16

1 Answer 1

1

From your question, it looks like you know how to use *args in function definition and you are looking for a way to pass all the elements of a list to that function regardless of the length of the list. If that's your question, then here's your answer:

def function(x, *args):
    print(x)
    print(args)

x = 10
l = [5, 6, 7, 8]
function(x, *l)

Output:

10
(5, 6, 7, 8)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.