Try our new documentation site (beta).


Gurobi tuple list. This is a sub-class of the Python list class that is designed to efficiently support a usage pattern that is quite common when building optimization models. In particular, if a tuplelist is populated with a list of tuples, the select function on this class efficiently selects tuples whose values match specified values in specified tuple fields. To give an example, the statement, '*', 5) would select all member tuples whose first field is equal to '1' and whose third field is equal to '5'. The '*' character is used as a wildcard to indicate that any value is acceptable in that field.

You generally build tuplelist objects in the same way you would build standard Python lists. For example, you can use the += operator to append a new list of items to an existing tuplelist, or the + operator to concatenate a pair of tuplelist objects. You can also call the append, extend, insert, pop, and remove functions.

To access the members of a tuplelist, you also use standard list functions. For example, l[0] returns the first member of a tuplelist, while l[0:10] returns a tuplelist containing the first ten members. You can also use len(l) to query the length of a list.

Note that tuplelist objects build and maintain a set of internal data structures to support efficient select operations. If you wish to reclaim the storage associated with these data structures, you can call the clean function.

A tuplelist is designed to store tuples containing scalar values (int, float, string, ...). It may produce unpredictable results with other Python objects, such as tuples of tuples. Thus, you can store (1, 2.0, 'abc') in a tuplelist, but you shouldn't store ((1, 2.0), 'abc').


Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.