stopwords=['are','is','my','what','a','am','of', 'to']
s=["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."]
words=[]
for sentence in s:
for word in sentence.split():
t=word.strip('.|,|?|!')
if t not in stopwords:
words.append(t)
count1={}
for word in words:
if word in count1.keys():
count1[word]+=1
else:
count1[word]=1
print(count1)
#判断语句中的单词多少,用字典实现
最新推荐文章于 2024-07-09 23:19:55 发布