def自定義函數統計統計字符串某單詞出現頻數

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import split
from collections import Counter

def wordCount():
    myString = ('my english name is thousand lee')
    list = myString.split()
    count = Counter(list)
    print(count)
    return
wordCount()

輸出結果

Counter({'my': 1, 'english': 1, 'name': 1, 'is': 1, 'thousand': 1, 'lee': 1})

Process finished with exit code 0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章