How to implement the following function foo
foo(2*i for i in [1, 3, 5]) # returning something like [(1, 2), (3, 6), (5, 10)]
I didn't know it is possible before I see the document of a third-party module.
The x
in the above link is just a special dict
called tupledict
. The following case is also legal.
model.addConstrs(i >= 0 for i in [4,3,2,0])
Out[32]:
{4: <gurobi.Constr *Awaiting Model Update*>,
3: <gurobi.Constr *Awaiting Model Update*>,
2: <gurobi.Constr *Awaiting Model Update*>,
0: <gurobi.Constr *Awaiting Model Update*>}
foo
method ? How to build the list you show in comment ?foo()
function to somehow get thex
values so it can combine them with the generated values.x
would be a special object which implements a lot of magic__dunder__
methods for specific operators. It cannot work whenx
is just a plain integer.