做leetcode题目的时候get到一个小知识点~
来自collections模块,主要用来跟踪值出现的次数
比如
>>>from collections import Counter
>>>str="aaabbbcccc"
>>>dict=Counter(str)
>>> dict
Counter({'c': 4, 'a': 3, 'b': 3})
>>> dict["c"]
4
>>>dict["d"]
0
做leetcode题目的时候get到一个小知识点~
来自collections模块,主要用来跟踪值出现的次数
比如
>>>from collections import Counter
>>>str="aaabbbcccc"
>>>dict=Counter(str)
>>> dict
Counter({'c': 4, 'a': 3, 'b': 3})
>>> dict["c"]
4
>>>dict["d"]
0