出现最多的是哪个词
运行下面这段程序:
words = ["苹果", "香蕉", "苹果", "梨", "香蕉", "苹果"]
count = {}
for w in words:
count[w] = count.get(w, 0) + 1
best = ""
for w in count:
if best == "" or count[w] > count[best]:
best = w
print(best)
运行下面这段程序:
words = ["苹果", "香蕉", "苹果", "梨", "香蕉", "苹果"]
count = {}
for w in words:
count[w] = count.get(w, 0) + 1
best = ""
for w in count:
if best == "" or count[w] > count[best]:
best = w
print(best)
全部评论