在dict理解中提出循环

时间:2016-04-18 10:28:23

标签: python dictionary count

这里第一次有人能告诉我如何将这个循环置于词典理解中吗?

counts = {}
for word in words:
    if word in counts:
        counts[word] = counts[word] + 1
    else:
        counts[word] = 1
print(counts)

0 个答案:

没有答案