1
當defaultdict對象上使用min()
,如果在一個字典計數字符串的索引用它奇怪返回最大。分鐘()上collections.defaultdict()返回最大計數
例如:
>>> import collections
>>> defaultdict=collections.defaultdict
>>> x=defaultdict(int)
>>> string="lol I am a lol noob"
>>> for k in string:
x[k]+=1
>>> x
defaultdict(<type 'int'>, {'a': 2, ' ': 5, 'b': 1, 'I': 1, 'm': 1, 'l': 4, 'o': 4, 'n': 1})
>>> min(x.items())
(' ', 5)
或者,如果你沒有實際需要的關鍵,只是'分鐘(x.values())' – wim
或'分鐘(X,鍵= x.get)'如果你只是想關鍵 –