Counter 计数字典


1年前 770次点击 来自 其他

标签: Python

from collections import Counter

# 计数
cnt = Counter()
for word in ['red','red','blue','green']
      cnt[word] +  = 1
print(cnt)
# Counter({'blue':1,'red':2,'green':1})

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1