理解Python/pill代码的片段

理解Python/pill代码的片段,python,pulp,Python,Pulp,我必须采用他们使用纸浆包装的现有脚本。我需要知道下面这行的结果是什么样子的: unit = ["one", "two", "three"] time = range(10) status=LpVariable.dicts("status",[(f,g) for f in unit for g in time],0,1,LpBinary) 这些键/值看起来如何 status["one"] = [0,1,1,1...]? 非常感谢你的帮助 from pulp import * unit = [

我必须采用他们使用纸浆包装的现有脚本。我需要知道下面这行的结果是什么样子的:

unit = ["one", "two", "three"]
time = range(10)

status=LpVariable.dicts("status",[(f,g) for f in unit for g in time],0,1,LpBinary)
这些键/值看起来如何

status["one"] = [0,1,1,1...]?
非常感谢你的帮助

from pulp import *
unit = ["one", "two"]
time = range(2)

status=LpVariable.dicts("status",[(f,g) for f in unit for g in time],0,1,LpBinary)
导致

>>> status

{('two', 1): status_('two',_1), 
('two', 2): status_('two',_2), 
('one', 2): status_('one',_2), 
('one', 0): status_('one',_0), 
('one', 1): status_('one',_1), 
('two', 0): status_('two',_0)}

因此,没有带有键“one”的条目。

这是有关的文档。你对代码的哪一部分特别困惑,列表理解?嘿!谢谢你的回复。我看了文档-但不幸的是,我不确定“状态”是什么样子(文档中也没有结果示例)您指的是状态,而不是“状态”,因为后者只是一个字符串,对吗?您能运行代码并进行反思吗?非常感谢您的回复!还有一个问题:“0,1,LpBinary”是什么意思?值必须是二进制文件吗?如上所述,dicts(name,indexs,lowBound=None,upBound=None,cat=0,indexStart=[])。对于cat–此变量所属的类别,整数、二进制或连续(默认)。状态_单位=[status[“one”,i]。时间为i的值()给我[None,None]-->这是否意味着该值(例如“status”(“Thou”),可以是0或1?要从字典中获取值,必须查询键。在这种情况下,它将是
状态[(“one”)“,1)]
要获得
状态('one','u1)
我建议您在试图理解词典之前,先开始查看python文档。