程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python counts word occurrences

編輯:Python
# coding=utf-8
# talk is cheap show me the code show me the code
""" 1、 The user enters a short English sentence 2、 Split string 3、 Loop processing 4、 Inquire about """
# The user enters a short English sentence 
msg = input(" Please enter the English characters you want to split ")
msg_list = msg.split() # Default space division 
# Declaration Dictionary 
dict_count = {
}
# print(msg_list)
# 3、 Loop processing 
for m in msg_list:
# Save to dictionary 
if m not in dict_count:
dict_count[m] = 1 # Words as our key,1 treat as value
else:
dict_count[m] += 1
# print(dict_count)
code = input(" Please enter the number of words to query :")
print("{} The number of occurrences of this word is : {} Time ".format(code, dict_count.get(code,0)))
# get Inside view code, without code, Default return 0


The content source :https://www.bilibili.com/video/BV1qh411W7HP?p=37&spm_id_from=pageDriver, If offended , Please let me know in time !Thanks*(・ω・)ノ
notes :2021/10/29


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved