哪种类型的列表最适合调用特定项目?

What type of list is best for calling specific items?

我在字典中有一个 space 的列表以及相关的平方英尺。我想调用每个项目并使用其面积通过简单的 area/width 方程形成维度...然后将维度与 space 名称重新关联。我了解到字典没有索引和排序。提前致谢!

#program areas
ticketing_sqft=600
galleries_sqft=12500
auditorium_sqft=2000
conference_sgft=1600


#dict of areas
sqft=dict(ticketing_sqft=600, galleries_sqft=12500, auditorium_sqft=2000,
      conference_sgft=1600)
program_names=list(sqft.keys())
areas=list(sqft.values())
areas.sort()

尝试这样的事情:

sq_dict = {"ticketing_sqft": 600, "galleries_sqft": 12500, "auditorium_sqft": 2000, "conference_sqft": 1600}

lenwid_dict = {}
for key in sq_dict:
    lenwid_dict[key] = [sq_dict[key]/2, sq_dict[key]/3] # any formula here

print lenwid_dict

基本上遍历我们的平方英尺字典中的 key/value 对,并根据对我们的平方英尺字典值的操作创建一个 length/width 字典。

让我们来定义你的字典:

>>> sqft=dict(ticketing_sqft=600, galleries_sqft=12500, auditorium_sqft=2000, conference_sgft=1600)

假设一个完美的正方形

现在,让我们制作一个字典,如果它是一个完美的正方形,该区域将具有的宽度和长度:

>>> wh = {bldg:(area**0.5, area**0.5) for (bldg, area) in sqft.items()}

新词典看起来像:

>>> print wh
{'auditorium_sqft': (44.721359549995796, 44.721359549995796), 'conference_sgft': (40.0, 40.0), 'ticketing_sqft': (24.49489742783178, 24.49489742783178), 'galleries_sqft': (111.80339887498948, 111.80339887498948)}

假设一个黄金矩形

古代数学家会争辩说,如果长方形的边长与 golden ratio 成正比,那么长方形看起来最好。如果您的建筑属于这种情况,请使用:

>>> r = (1 + 5**0.5)/2
>>> wh = {bldg:((area/r)**0.5, (area*r)**0.5) for (bldg, area) in sqft.items()}
>>> print wh
{'auditorium_sqft': (35.15775842541429, 56.88644810057831), 'conference_sgft': (31.446055110296932, 50.880785980562756), 'ticketing_sqft': (19.256697360916718, 31.15799084103365), 'galleries_sqft': (87.89439606353574, 142.21612025144577)}