How to use HashMap in Python?

0 votes

I want to implement a HashMap in Python.

I want to ask a user for an input. Now, 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", "ABC");
   streetno.put("2", "DEF");
   streetno.put("3","GHI");
   streetno.put("4","JKL");
   streetno.put("5","MNO")

Oct 26, 2018 in Python by findingbugs
• 3,140 points
707 views

1 answer to this question.

0 votes

You can use Python dictionary it is a built-in type that supports key-value pairs.

streetno = {"1":"ABC", "2":"DEF", "3":"GHI", "4":"JKL","5":"MNO"}

as well as using the dict keyword:

streetno = dict({"1":"ABC", "2":"DEF"}) 

or:

streetno = {}
streetno["1"] = "ABC" 
This will help your need.
answered Oct 26, 2018 by Priyaj
• 56,160 points

Related Questions In Python

0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 56,160 points
39 views
+1 vote
2 answers

How to use the pass statement in Python

In Python programming, pass is a null statement. The ...READ MORE

answered Apr 5 in Python by anonymous
46 views
0 votes
1 answer

how to use Binary tree search in Python

The key thing to notice is that ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 56,160 points
54 views
0 votes
1 answer

How to use multiprocessing queue in Python?

This is a simple example of a ...READ MORE

answered Oct 25, 2018 in Python by SDeb
• 12,360 points
182 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 128 views
+4 votes
6 answers
0 votes
2 answers

How to use threading in Python?

 Thread is the smallest unit of processing that ...READ MORE

answered Apr 6 in Python by anonymous
64 views
0 votes
1 answer

How to use “raise” keyword in Python

You can use it to raise errors ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 56,160 points
27 views