Hash Map in Python

后端 未结 9 1091
礼貌的吻别
礼貌的吻别 2020-11-27 10:59

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 k

9条回答
  •  心在旅途
    2020-11-27 11:19

    It's built-in for Python. See dictionaries.

    Based on your example:

    streetno = {"1": "Sachine Tendulkar",
                "2": "Dravid",
                "3": "Sehwag",
                "4": "Laxman",
                "5": "Kohli" }
    

    You could then access it like so:

    sachine = streetno["1"]
    

    Also worth mentioning: it can use any non-mutable data type as a key. That is, it can use a tuple, boolean, or string as a key.

提交回复
热议问题