# coding=utf-8
# talk is cheap show me the code show me the code
""" 1、用戶輸入英文短句 2、分割字符串 3、循環處理 4、查詢 """
# 用戶輸入英文短句
msg = input("請輸入你想要分割的英文字符")
msg_list = msg.split() # 默認空格分割
# 聲明字典
dict_count = {
}
# print(msg_list)
# 3、循環處理
for m in msg_list:
# 儲存到字典中
if m not in dict_count:
dict_count[m] = 1 # 單詞當做我們的key,1當做value
else:
dict_count[m] += 1
# print(dict_count)
code = input("請輸入要查詢次數的單詞:")
print("{}該單詞出現點次數為: {}次".format(code, dict_count.get(code,0)))
# get裡面查看code,如果沒有code,默認返回0
該內容來源:https://www.bilibili.com/video/BV1qh411W7HP?p=37&spm_id_from=pageDriver,如有冒犯,請及時告知!Thanks*(・ω・)ノ
注:2021/10/29