Python中的哈希映射 [英] Hash Map in Python
本文介绍了Python中的哈希映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Python中实现一个HashMap。我想要求用户输入。取决于他的输入,我从HashMap中检索一些信息。如果用户输入HashMap的键值,我想检索相应的值。
如何在Python中实现此功能?
HashMap< String,String> streetno = new HashMap< String,String>();
streetno.put(1,Sachin Tendulkar);
streetno.put(2,Dravid);
streetno.put(3,Sehwag);
streetno.put(4,Laxman);
streetno.put(5,Kohli)
解决方案 div>
Python字典是一种内置类型,它支持键 -
streetno = {1:Sachine Tendulkar,2:Dravid,3 :Sehwag,4:Laxman,5:Kohli}
以及使用dict关键字:
streetno = dict({1:Sachine Tendulkar,2 Dravid})
或:
streetno = {}
streetno [1] =Sachine Tendulkar
I want to implement a HashMap in Python. I want to ask a user for an input. depending on his input I am retrieving some information from the HashMap. If the user enters a key of the HashMap, I would like to retrieve the corresponding value.
How do I implement this functionality in Python?
HashMap<String,String> streetno=new HashMap<String,String>();
streetno.put("1", "Sachin Tendulkar");
streetno.put("2", "Dravid");
streetno.put("3","Sehwag");
streetno.put("4","Laxman");
streetno.put("5","Kohli")
解决方案
Python dictionary is a built-in type that supports key-value pairs.
streetno = {"1":"Sachine Tendulkar", "2":"Dravid", "3":"Sehwag", "4":"Laxman","5":"Kohli"}
as well as using the dict keyword:
streetno = dict({"1":"Sachine Tendulkar", "2":"Dravid"})
or:
streetno = {}
streetno["1"] = "Sachine Tendulkar"
这篇关于Python中的哈希映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文