zoukankan      html  css  js  c++  java
  • 综合练习:英文词频统计

    1. 词频统计预处理
    2. 下载一首英文的歌词或文章
    3. 将所有,.?!’:等分隔符全部替换为空格
    4. 将所有大写转换为小写
    5. 生成单词列表
    6. 生成词频统计
    7. 排序
    8. 排除语法型词汇,代词、冠词、连词
    9. 输出词频最大TOP10
    word = '''
    It's the most controversial Formula One introduction since the 2016 qualifying elimination clock. But unlike that ill-fated change, the halo should last more than two races.
    Formally known as the "cockpit head protection system," the halo is proving highly divisive.
    Team principals, drivers and fans are split over whether it is the right safety solution when the new grand prix season roars to life in Melbourne this week.
    After years of research and development, FIA settled on the halo - a thong-like titanium and carbon-fibre structure above the cockpit - to protect drivers from flying debris following the fatal crashes of Jules Bianchi at the 2014 Japanese Grand Prix and Justin Wilson in an IndyCar race in the US the following year.
    Mercedes team boss Toto Wolff is firmly among the halo haters. "If you give me a chainsaw I would take it off," he said at the launch of the team's 2018 car last month.
    "I think we need to look after the driver's safety, but we need to come up with a solution that simply looks better," he added.
    Motor racing purists are aghast because they say grand prix racing is supposed to be an open-cockpit formula; other fans moan it is just plain ugly; some drivers have said it restricts vision.
    World champion Lewis Hamilton doesn't like the halo's look, but said: "We have known for some time it was coming and I think after a few races we will forget it is even there."
    '''
    
    symbol = [",", ".", "!", "?", "'", ":", "-"]
    for i in symbol:
        word = word.replace(i, '')
    
    newword = word.lower()
    split
    = word.split() newsword = {} for i in split: count = word.count(i) newsword[i] = count delwords = ''' a an the in on to at and of is was are were i he she you your they us their our it or for be too do no that s so as but it's ''' prep = delwords.split() for i in prep: if i in newsword.keys(): del (newsword[i])
    newsword
    = sorted(newsword.items(), key=lambda items: items[1], reverse=True)
    for i in range(10): print(newsword[i])
  • 相关阅读:
    [解题报告]256 Quirksome Squares
    [解题报告]369 Combinations
    [解题报告]10696 f91
    [解题报告]483 Word Scramble
    [解题报告]10041 Vito's Family
    [解题报告]686 Goldbach's Conjecture (II)
    [解题报告]151 Power Crisis
    [解题报告]10079 Pizza Cutting
    [解题报告]495 Fibonacci Freeze
    [解题报告]541 Error Correction
  • 原文地址:https://www.cnblogs.com/BennyKuang/p/8625589.html
Copyright © 2011-2022 走看看