Tupledict with lists for values
AnsweredHello!
I am trying to create a tupledict() where :
("Type A" , "Time period 1") , ("Type B" , "Time period 1") etc are the keys and the corresponding values are in the form of lists. Let us consider an example of 5 elements with values (5,10,15,20,21) and (3,6,9,12,15) respectively.
When I am referring to this tupledict in a constraint, how do I access each of the values in the list/ refer to them separately as an index? For example, I want to refer to the following:
("Type A", "Time period 1", "Element 1") : 5
("Type A", "Time period 1", "Element 2") : 10
("Type A", "Time period 1", "Element 3") : 5
etc.
Normally, I would type this out but I am dealing with a list which is significantly larger than 5 elements. How can I proceed with this?
Thank you in advance!
-
Hi Pavithra,
Let values be the list of the elements, (5, 10, 15, 20, 21) in your example. You can just write:
d = tupledict([(("Type A", "Time period 1", index), value) for
index, value in enumerate(values)])Then \(\texttt{d}\) will be:
{
('Type A', 'Time period 1', 0): 5, ('Type A', 'Time period 1', 1): 10,
('Type A', 'Time period 1', 2): 15, ('Type A', 'Time period 1', 3): 20,
('Type A', 'Time period 1', 4): 21
}
Best regards,Maliheh
0
Please sign in to leave a comment.
Comments
1 comment