Hash Map in Python

后端 未结 9 1072
礼貌的吻别
礼貌的吻别 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:09

    Python Counter is also a good option in this case:

    from collections import Counter
    
    counter = Counter(["Sachin Tendulkar", "Sachin Tendulkar", "other things"])
    
    print(counter)
    

    This returns a dict with the count of each element in the list:

    Counter({'Sachin Tendulkar': 2, 'other things': 1})
    

提交回复
热议问题