簡體   English   中英

尋找合適的python數據結構

[英]looking for the appropriate python data structure

我正在尋找與字典等效的python 2.7數據結構,但可以在其中關聯多個鍵。

例如,我想關聯:

  • 汽車:-雪佛蘭-豐田-悍馬-法拉利
  • 計算機:-mac -windows -linux -amstrad

我需要能夠使用myDictionary.has('cars')類的東西在字典中搜索字符串'cars'或'computers'或其他字符串

for key in myDictionary:使用for key in myDictionary:與汽車對應的所有鍵for key in myDictionary:

您是否正在尋找將字符串映射到列表的字典?

>>> d = {"cars": ["Chevrolet", "Toyota", "Hummer", "Ferrari"],
         "computers": ["mac", "windows", "linux", "amstrad"]}
>>> d["cars"]
['Chevrolet', 'Toyota', 'Hummer', 'Ferrari']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM