2018年10月30日

字频统计2-字符串中有标点符号

摘要: sentence="知之,为知之。不知,为不知。" #第1步:将各种标点符号统一替换为空窜for i in [",","。"]: sentence=sentence.replace(i,"")print(sentence) #第2步:进行字频统计dict1={}for s in sentence: 阅读全文

posted @ 2018-10-30 09:30 Python大数据 阅读(354) 评论(0) 推荐(0) 编辑

字频统计1-字符串中没有标点符号

摘要: sentence="知之为知之不知为不知"dict1={}for s in sentence: dict1[s]=dict1.setdefault(s,0)+1print(dict1) 其中,setdefault(s,0)的作用是:如果dict1中存在键s时,就返回键s的值(某个字的频率);如果di 阅读全文

posted @ 2018-10-30 09:24 Python大数据 阅读(294) 评论(0) 推荐(0) 编辑

导航