-2

As my original question was closed due to 'not being minimalistic', I will explain what I want to do by giving you an example that I have made up.

I have a function called 'persona()' and this function has argument called 'alpha', 'beta', 'gamma' that just gets bool as its value (true or false) like this:

face = persona(alpha=true, beta=false, gamma=false)

and I have a list that looks like below because I had no other option to get it otherwise.

ar_list = ['alpha', 'beta', 'gamma']
ar_column = ['a', 'b', 'c', 'd']

If I want to get element in ar_list as an argument name of function persona(), how can I achieve this? Below was what I 'hoped' to do, but this surely will not work. But I hope there are ways to achieve something like this.

for ar in ar_column:
    pesona(ar_list[0] = (some calculation using 'alpha' and ar),
           ar_list[1] = (some calculation using 'beta' and ar),
           ar_list[2] = (some calculation using 'gamma' and ar))
Haidus
  • 63
  • 8
  • Have you tried doing `persona(*ar_list)` ? – HenriChab Mar 19 '21 at 00:25
  • you can directly pass list to function `persona(ar_list)` or if you want to pass it as separate variable than pass it as *argv that is `persona(*argv)` – Rima Mar 19 '21 at 00:26
  • 1
    It's not really clear what you are asking. You say the arguments to your function are bools, but then you say you want to pass a list of strings as arguments to the function. A little more code with your intended result would be helpful here. – Mark Mar 19 '21 at 00:27
  • @HenriChab I don't think that's what he's after. As far as I understand his question, he wants the strings in the list to be the names of variables of type boolean. – Andy Sukowski-Bang Mar 19 '21 at 00:28
  • Your request is unclear. You claim that you have an argument with a name that is a tuple of three strings; this is not legal Python. Then you imply that you want to pass a list of those strings to your function; this is covered in any tutorial on functions, so I expect that you want something else. You also say that you want the function argument to "get" a Boolean value -- which would be a trivial lesson from the same tutorial. – Prune Mar 19 '21 at 00:30
  • @AndySukowski-Bang Yop, you're right, even though I tried to understand very hard, still not sure what he really wants to do. – HenriChab Mar 19 '21 at 00:31
  • @HenriChab Edited my question for everyone else didn't understand – Haidus Mar 19 '21 at 00:54
  • @AndySukowski-Bang How about now? – Haidus Mar 19 '21 at 00:55
  • If you want the alpha argument to get the string "alpha" and the beta argument to get the string "beta" and the gamma argument to get the string "gamma", then @HenriChab's original comment was exactly right, `persona(*ar_list)`. – Tim Roberts Mar 19 '21 at 00:55
  • @Prune If what I wanted to know was in something that you said, I didn't just posted my question here. Wonder if you got it after I edited my question now. – Haidus Mar 19 '21 at 00:57
  • @Haidus There is probably a better way to do it, than to create dynamic variables. But if it's really necessary, have a look at [this question](https://stackoverflow.com/questions/1373164). – Andy Sukowski-Bang Mar 19 '21 at 01:04
  • @AndySukowski-Bang Thanks, but definitely not meant that. I added some context hoping for others to better understand my question – Haidus Mar 19 '21 at 01:27

2 Answers2

0

Not sure you are looking for this :

Extended Iterable Unpacking

Here *a, can have more than one variables and passing it to function. Than unpacking it in function.

*a, = True, False, True

def persona (*a):
    alpha, beta, gamma = a
    print(alpha, beta, gamma)

persona(*a)
Rima
  • 1,447
  • 1
  • 6
  • 12
0
for ar in ar_column:
    ar_dict = {i:(some calculation using 'alpha' and ar) for i in ar_list}
    persona(**ar_dict)
scp10011
  • 136
  • 3