推导式构建字典
dic = {i:i**2 for i in range(10)}
re.sub('')
集合
set()
内部元素无序,不重复
dic = {i:words.count(i) for i in word}
推导式构建字典
dic = {i:i**2 for i in range(10)}
re.sub('')
集合
set()
内部元素无序,不重复
dic = {i:words.count(i) for i in word}
lyric.split()。以空格切割
lyric.lower(). 大写变小写
dic={i:i**2 for i in range(10)}
import re
lyric=re.sub('[,.?:;"\'],'',lyric)把标点符号变成空
统计lyric中的单词出现的频率
word=lyric.split()
word=set(words)
dic={i:words.count(i) for i in word}
import re
str="Each human being is born As something new, Something that never existed? before"
print(str)
str1=str.lower() #统一大小写
word=re.sub('[,?]',"",str1)#运用正则表达式替换掉句子中的特殊符号
words=word.split(" ") #以空格作为分隔符,将字符串转换为以单词为元素的列表
set1=set(words) #将列表转化为不包含重复元素的集合
dict={i:words.count(i) for i in set1}
print(dict)
lyric='the night begin'
字典的键值对
dic={i:i**2 for i in range()}
断句取词
words=lyric.split()
大写切换小写
import re
lylic='Words.......'
lylic.lower()
(符号)替换
lylic=re.sub('[进行替换的对象],'替换成什么',对谁操作)
词频的统计
dic={i:word.counts(i) for i in word}
set()
集合:元素不重复,无序
lower