from collections import Counter
tlist = [1,2,1,3,2,'1']
Counter(tlist)
Out[13]: Counter({1: 2, '1': 1, 2: 2, 3: 1})
type(Counter(tlist))
Out[14]: collections.Counter
dict(Counter(tlist))
Out[15]: {1: 2, '1': 1, 2: 2, 3: 1}
from collections import Counter
tlist = [1,2,1,3,2,'1']
Counter(tlist)
Out[13]: Counter({1: 2, '1': 1, 2: 2, 3: 1})
type(Counter(tlist))
Out[14]: collections.Counter
dict(Counter(tlist))
Out[15]: {1: 2, '1': 1, 2: 2, 3: 1}
本文标题:列表元素计数
本文链接:https://www.haomeiwen.com/subject/enlkwxtx.html
网友评论