1. 程式人生 > 其它 >Gurobi Python API簡介:multidict()

Gurobi Python API簡介:multidict()

multidict()

multidict(data)

This function splits a single dictionary into multiple dictionaries.
(這個函式將一個字典拆分成多個字典.)
The input dictionary should map each key to a list of n values.
(輸入的字典應當將每個鍵對映到由n個值組成的列表)
The function returns a list of the shared keys as its first result, followed by the n individual Gurobi tuple dictionaries

(stored as tupledict objects).
(這個函式返回的第一個結果是:一個由構成的列表

Arguments:
data: A Python dictionary. Each key should map to a list of values.
Return value:
A list, where the first member contains the shared key values, and the following members contain the dictionaries that result from splitting the value lists from the input dictionary.

Example usage:

import gurobipy as gp

keys, dict1, dict2 = gp.multidict({'key1': [1, 2], 'key2': [1, 3], 'key3': [1, 4]})

print('keys:')
print(keys)
print('dict1:')
print(dict1)
print('dict2:')
print(dict2)

Output:

keys:
['key1', 'key2', 'key3']
dict1:
{'key1': 1, 'key2': 1, 'key3': 1}
dict2:
{'key1'
: 2, 'key2': 3, 'key3': 4} Process finished with exit code 0