Streets= [{"index": 1, "name": "east 13th", "location": ["pizza store", "shoe store"]},
{"index": 2, "name": "east 14th", "location": ["pizza store", "flower store"]},
{"index": 3, "name": "east 15th", "location": ["shoe store", "massage parlor"]},
{"index": 4, "name": "east 16th", "location": "shoe store"}]在东14街的地方怎么打印呢?我尝试过print Streets.values(),但这似乎不起作用-当列表中只有一个数组,而不是四个数组(看起来)时,它就会起作用。
另外,我想要将需求映射到位置。例如,当用户“走进”东15街的一家鞋店时,另一个列表是:
需求={饥饿,口渴,衣着,住所}
减少了“衣物”。而且,如果一个人在没有“衣服”需要的情况下试图再次进入鞋店,程序将返回如下输出
“你看着这些东西,意识到你不需要他们能提供的任何东西。”
这里不是以代码的形式键入它,我会像下面这样写一些东西:
If the user tries to enter into the location
Check what needs are mapped to that location
If the needs which are mapped to that location are currently unmet
The user enters in to that location and interacts with the 'shop keep'
If the needs which are mapped to that location are currently met
The user enters in to that location, looks around, and leaves.
Go back to default state那么,我如何将“饥饿”需求映射到位于“东13号”的“披萨店”和位于“东14号”的“披萨店”呢?
发布于 2015-09-23 02:40:38
你有一个有字典的列表。您可以循环列表,并在每个列表中搜索所需的键和值
for d in Streets:
if d["name"] == "east 14th":
print(d["location"])输出
‘披萨店’,‘花店’
https://stackoverflow.com/questions/32723850
复制相似问题