python 基础 字典 小例子

统计单词次数 作为字典存储

cotent = "who have an apple apple is free free is money you know" result = {} for s in content.split(""): if s in result: result[s] + =1 else: result[s] = 1 print result

反转上面的结果
res = {}
for k,v in result.items():
  res.setdefault(v,[])
  res[v].append(k)

 

posted @ 2017-10-29 21:49  一只宅男的自我修养  阅读(343)  评论(0编辑  收藏  举报