Title: Using a list as parameters for a function
Tags: python
Question: I'm have a list like this ['a1,b1,c1', 'a2,b2,c2', 'a3,b3,d3']
and I'm trying to either write a function or a for loop that will take each set up these numbers as inputs
so for example the first time it runs a=a1, b=b1, c=c1, the second time it'll run a=a2, b=b2 c=c2 as inputs
I've seen a few threads using functions with asterisks like this some_func(*params)
but I don't see how to make it a loop that kind of takes a combination of inputs like how I wanted it to
or would using a dict be able to address and do this?
an example would be like (sorry not making it superr specific and concrete)
def apply(a, b, c):
x = something
y = something_else
(hello, there) = somefunction(x, y, size=a)
sky = anotherfunction(beta[1], put=b, call=c)
any help is appreciated, or if there has been a similar question before, happy for it to be linked
Comment: There is not inbuild method developed to achieve something like this, you need to have two methods, an outer and an inner method, outer calls the inner method by looping over the ith indices of each array

Comment: You have a string with commas as input - you would need to parse it first.

Comment: thanks, yeah I'm using a1 here to represent else putting all the numbers here makes it more confusing?

Comment: as in, turn them into separate lists?

Comment: yep, with possible repetitive numbers like `["1,2,3", "1,5,6"]`

Comment: a1 is not a number

Comment: So the list is something like `["1,2,3", "4,5,6"]`?

Here is the accepted answer: Suppose you have a list strings and function func
strings = ['a1,b1,c1', 'a2,b2,c2', 'a3,b3,d3']
def func(a, b, c):
# your function
pass
Structure will be
for string in string:
func(*map(int, string.split(&quot;,&quot;)))
the map(int, string.split(&quot;,&quot;)) will split string and make a list like [1, 2, 3] for '1,2,3'.
Then the * symbol will spread the numbers one for each parameter, for list [1, 2, 3] will call the function like func(a=1, b=2, c=3).
Comment for this answer: @jaxan I think it depends on you and what you need to do
Comment for this answer: @jaxan if you want to do that, you can write `[(int(x) if x.isnumeric() else float(x)) for x in string.split(',')]` in one line instead of the map, you can also do a multiline on your own.
Comment for this answer: hello, just an add-on question, if say some value in `a, b, c` is a float, would they be able to be float and intergers as they are, or I must decide whether to keep them as float or intergers at the `func(*map(int, string.split(",")))`?

Here is another answer: If I understood correctly, use variadic arguments as follows:
def fun(*args):
&quot;&quot;&quot;Toy function&quot;&quot;&quot;
return sum(args) + 10
arguments = [&quot;1,2,3&quot;, &quot;1,5,6&quot;]
for argument in arguments:
res = fun(*map(int, argument.split(&quot;,&quot;)))
print(res)
Output
The expression:
map(int, argument.split(&quot;,&quot;))
creates an iterable of integers from the argument string. The * unpacks these arguments.
Comment for this answer: thanks! but what if in the case where the a, b and c is spreaded out in the function? like say `test = 1 + 2 + a `------------ `test2 = b` ----------- `hello = (x = 1, y =2, z =c)`, would this also be able to work?
Comment for this answer: say like instead of being able to use `sum(args)`, `a, b, c` is used differently (called different times, and maybe even multiple times inside the function)
Comment for this answer: sorry for making it confusing
Comment for this answer: I kind of edited the question abit including an example, but it's still not entirely specific, would this kind of make more sense? thanks!!
Comment for this answer: thanks dani for trying to help as well!! again sorry I'm dumb and creating all those unnecessary confusion
Comment for this answer: Sorry, but I do not understand those examples
Comment for this answer: Perhaps if you add a few more *concrete* examples, it would help me and others understand your question better

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 7, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:10/08/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python>', 'Title': 'Using a list as parameters for a function', 'ViewCount': 73, 'id': 69499748, 'user_AboutMe': None, 'user_AccountId': 19488793.0, 'user_DisplayName': 'jaxan', 'user_Reputation': 35.0, 'user_Views': 2.0, 'user_id': 14257460.0}}