统计词频 -- Python

'''
统计词频
'''


def count_words(l):
    dic = {}
    for word in l:
        if word not in dic:
            dic[word] = 1
        else:
            dic[word] += 1
    return dic


if __name__ == '__main__':
    line = 'i want go to the beijing beijing'
    l = line.split()
    res = count_words(l)
    print(res)

猜你喜欢

转载自blog.csdn.net/zdz0200/article/details/82882968