我能够通过以下方式建立字数词典:
dicc = {}
for word in splitt:
if word not in dicc:
dicc[word]=0
if word in dicc:
dicc[word]+=1
我正试着用字典来理解它。
以下声明有效:
countDicc = {word:(0 if word not in countDicc else +1) for word in splitt}
显然,我需要+=1
让字典发挥作用,然而,这句话是无效的;如何在字典理解中实现+=
Tags:
使用计数器
相关问题 更多 >
编程相关推荐