Mar-09-2020, 07:50 AM
Of course. The standard library includes the
Also, it sounds like having two separate lists is not what you want. Why not just have a dict that maps the symbol to the function instead?
operator
module that has functions for those basic mathematical operations, e.g.>>> import operator >>> f = operator.add >>> f(1, 2) 3 >>> f = operator.mul >>> f(2, 3) 6 >>>It's really useful to be able to treat functions as values in the same way that, say, integers are values - being able to pass them around, or assign them to variables as I'm doing here.
Also, it sounds like having two separate lists is not what you want. Why not just have a dict that maps the symbol to the function instead?