Passing variable length parameters to a function in python
NickName:user2497586 Ask DateTime:2013-11-08T03:42:02

Passing variable length parameters to a function in python

This question, though specific in nature, can be abstracted to a general question about Python.

Imagine there is a function that takes in a few parameters. This list of parameters is of variable length; however, the types of the given parameters are not variable. The parameters come in groups of three, and the first and second are lists of floats and the third is a string. Then it repeats. So, in a way, the parameters are not of variable length, it's restricted to multiples of 3.

The types can be anything, those are just the ones specific to my problem. I have a matplotlib plot function that looks like this in the docs:

a.plot(x1, y1, 'g^', x2, y2, 'g-',...)

As you can see, number of groups of three can be however long you want.

I have a list of lists that contains all of my x values (x1, x2, x3, ...) and a list of lists that contain all of my y values (y1, y2, y3,...). Not knowing how long those lists are (they are always equal in length to each other, though), and assuming I can have some dictionary that maps certain indexes to certain strings (for the string parameter), how can I pass indexes from variables length list of lists to this function.

Ideally, I guess it would look something like this is pseudo-code:

for element in list_of_lists:
    myFunction(lists_of_lists[element])

Except that this code would just execute the myFunction for all the elements in the list_of_lists. Instead, I want one long list of parameters and only execute the function once. I also feel like this problem is interested for Python as a whole, not just my specific issue. Thanks in advance!

Copyright Notice:Content Author:「user2497586」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19845132/passing-variable-length-parameters-to-a-function-in-python

More about “Passing variable length parameters to a function in python” related questions

Passing variable length parameters to a function in python

This question, though specific in nature, can be abstracted to a general question about Python. Imagine there is a function that takes in a few parameters. This list of parameters is of variable ...

Show Detail

Passing an arbitrary number of parameters to a function in python

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...

Show Detail

Passing parameters to a wrapper in python through variables

Is it possible to send parameters through a variable to wrapper in python? The wrapper I am using works properly when parameters are provided directly. For example: ClustalOmegaCommandline(infile...

Show Detail

scilab, passing parameters to the function and changing variable type

I'm trying to build a GUI to output plots for control system design when input parameters of transfer function.I got some problems on passing parameters to the function and changing variable type. ...

Show Detail

scilab, passing parameters to the function and changing variable type

I'm trying to build a GUI to output plots for control system design when input parameters of transfer function.I got some problems on passing parameters to the function and changing variable type. ...

Show Detail

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a

Show Detail

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a

Show Detail

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a

Show Detail

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a

Show Detail

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a

Show Detail