# dic={'purple':'紫色'}
# dic['black']='黑色'
# for key,val in dic.items():
# print(key)
# 单词统计
stopword=['are','is','my','what','a','am','of', 'to']
s1=["What is deep learning?","Deep learning is a subset of machine learning, which is essentially a neural network with three or more layers.", " These neural networks attempt to simulate the behavior of the human brain—albeit far from matching \ its ability—allowing it to learning from large amounts of data."]
s=s1[0]+' '+s1[1]+' '+s1[2]
words = s.split() # 把文章以空格分开成列表
new_word = []
for word in words:
t = word.strip(',|?|.|!')#去除掉标点符号
if t not in stopword:#去除停用词
new_word.append(t)#清洗后的单词
count={}
for i in new_word:#把单词带入i
if i in count:#如果单词存在在列表count
count[i]+=1#单词量加1
else:
count[i]=1#如果单词不存在在列表count,放入类别
# print(count)
max=0
for i in new_word:
if new_word.count(i)>max:#new_word.count(i) 统计i出现的次数
t=i
max=new_word.count(i)
# print(t,max)
set1={'1','2'}#集合去重
word1=set(new_word)
# word1=list(new_word)
print(type(set1))
#逢七拍手
#素数判断 除了1和他本身能够被整除
#歌德巴赫猜想 任何一个大于2的偶数,都可以表示成两个素数的和
#单词统计 去除标点符合和号和停用词
#统计高频词汇
#去除重复词汇
python复习2
于 2023-12-18 15:04:44 首次发布