Python implementation upgrade: determine the number of occurrences of each word
str1 ='i am a luck dog , you are a luck dog ! my life is short, i use python, you ?'
dc ={
}# 首先还是以空格分出来 单词
l1 = str1.split()# 列表元素去重
l2 =list(set(l1))for i in l2:# 统计单词出现次数,并存入字典
dc[i]= l1.count(i)print(dc)
Generally speaking, there are many methods provided by python, and you must be familiar with these methods.
To solve problems in C language, first think about the steps and algorithm rules. Python solves the problem, as long as you come up with the overall idea, and then many detailed steps will be encapsulated, and you can find and use it directly.