0
我想打印一個字一個字符串中出現的次數發生了一句話,這是我的代碼:打印多少次在一個字符串
count = 0
wordfreq = 0
sentence = input("Enter a sentence: ")
word = input("Enter a word within the setence: ")
sentence2 = sentence.split()
wordcount = [sentence2.count.(word) for word in sentence2]
print (wordcount)
然而,當我運行該程序,並輸入我希望它計算它發生的次數,代碼以它所表達的次數和次數的格式返回它。
舉例來說,如果我有「這是一個句子,我喜歡寫一個句子]
,我想選字是‘一’,它將返回[2,2],而我希望它只是返回[2]。
如果使用使用的語言標記問題,它會有所幫助。 – Pullie