自己写的和标准库对得上吗
运行下面这段程序:
from collections import Counter
def word_count(words):
c = {}
for w in words:
c[w] = c.get(w, 0) + 1
return c
words = ["苹果", "香蕉", "苹果", "梨", "香蕉", "苹果"]
print(word_count(words) == dict(Counter(words)))
运行下面这段程序:
from collections import Counter
def word_count(words):
c = {}
for w in words:
c[w] = c.get(w, 0) + 1
return c
words = ["苹果", "香蕉", "苹果", "梨", "香蕉", "苹果"]
print(word_count(words) == dict(Counter(words)))
全部评论