Python Word frequency statistics

Source: Internet
Author: User


Word Frequency Statistics pretreatment
Download a lyrics or article in English
Will all,.?! ': equal separators are all replaced with spaces
Convert all uppercase letters to lowercase
Generate a word list
Generate Word Frequency statistics
Sort
Exclude grammatical words, pronouns, articles, conjunctions
Output word frequency max TOP10

S= ' Robert Zoellick, a former US trade representative and head of the world Bank, once said: "Trade is more about politics than economics. " Indeed, international trade among nations are all on business, but once politicians step in, it becomes polarizing with Unexpected consequences that could leads to a trade war. ' \
' The ever-boastful US President Donald Trump tweeted that ' Trade wars is good, and easy to win. His newly appointed top economic advisor, Larry Kudlow, should remind him the trade wars is a pyrrhic form of competitio N in which even the victor was left worse off.
' The US Constitution clearly states: ' Congress shall regulate interstate and foreign commerce. ' It grants authority to the executive branch to negotiate trade agreements, but it had the last word on increasing tariffs, Whether it but Trump have no patience to follow such procedures. Instead He is issuing executive orders to satisfy his political base. ' \
' The Republicans in Congress were shocked this their leader would take such a protectionist action, recognizing it was mor E about politics than national security. Their swift opposition forced Trump to make Canada and Mexico exceptions (to is part of the North American free trade agreemen T negotiations), and eventually minimize the effects on the US ' \
' There'll is not being a trade war with these countries. If It occurs, it'll be and China. The Trump administration has already taken shots, the could spark a trade war, including slapping tariffs on solar panels. The next, and most fierce, battlefield in today's smartphones to enter the US market. Around the corner is sections 301 of the trade Act of 1974-originally intended to safeguard patent rights-that would giv E The US President the authority to limit China '
S1=s.replace ('? ', ')
S2=s1.replace (': ', ')
S3=s2.replace (', ', ')
S4=s3.replace ('! ', ')
S5=s4.replace (",")
S6=s5.replace (' "', ')
S7=s6.replace ('-', ')
S8=s7.replace ('. ', ')
S9=s8.lower ()
List1=s9.split ()
For I in List1:
Print (i)
Myset=set (List1)
Print (MySet)
key={}
For I in MySet:
Key[i]=list1.count (i)
Print (Key[i])
For i in {' A ', ' an ', ' the ', ' to ', ' in ', ' on ', ' was ', ' is ', ' too ', ' AM '}:
If I in key:
Key.pop (i)
Sort=sorted (Key.items (), Key=lambda d:d[1],reverse=true)
For j in Range (10):
Print (Sort[j])

Python Word frequency statistics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.