首页 > 技术文章 > Python3 Wordcount

RHadoop-Hive 2018-12-20 17:55 原文

# 定义字符串
context = """The US media reports suggest Robert Mueller's inquiry has taken the first step towards possible criminal charges.
According to Reuters news agency, the jury has issued subpoenas over a June 2016 meeting between President Donald Trump's son and a Russian lawyer.
The president has poured scorn on any suggestion his team colluded with the Kremlin to beat Hillary Clinton.
In the US, grand juries are set up to consider whether evidence in any case is strong enough to issue indictments for a criminal trial. They do not decide the innocence or guilt of a potential defendant.
The panel of ordinary citizens also allows a prosecutor to issue subpoenas, a legal writ, to obtain documents or compel witness testimony under oath.
Trump: US-Russia relations are at 'dangerous low'
The Trump-Russia saga in 200 words
Russia: The 'cloud' over the White House
Now it's deadly serious
Anthony Zurcher, BBC North America reporter
Robert Mueller's special counsel investigation has always been a concern for the Trump administration. Now it's deadly serious business.
With the news that a grand jury has been convened in Washington DC, and that it is looking into the June 2016 meeting between Donald Trump Jr and Russian nationals, it's clear the investigation is focusing on the president's inner circle.
This news shouldn't come as a huge shock, given that Mr Mueller has been staffing up with veteran criminal prosecutors and investigators. It is, however, a necessary step that could eventually lead to criminal indictments. At the very least it's a sign that Mr Mueller could be on the trail of something big - expanding the scope beyond former National Security Adviser Michael Flynn and his questionable lobbying. It also indicates his investigation is not going to go away anytime soon.
In the past, when big news about the Russia investigation has been revealed, Mr Trump has escalated his rhetoric and taken dead aim at his perceived adversaries. The pressure is being applied to the president. How will he respond?
At a rally in Huntington, West Virginia, on Thursday evening, Mr Trump said the allegations were a "hoax" that were "demeaning to our country".
"The Russia story is a total fabrication," he said. "It's just an excuse for the greatest loss in the history of American politics, that's all it is."
The crowd went wild as he continued: "What the prosecutor should be looking at are Hillary Clinton's 33,000 deleted emails."
"Most people know there were no Russians in our campaign," he added. "There never were. We didn't win because of Russia, we won because of you, that I can tell you."
Mr Trump's high-powered legal team fielding questions on the Russia inquiry said there was no reason to believe the president himself is under investigation.
Ty Cobb, a lawyer appointed last month as White House special counsel, said in a statement: "The White House favours anything that accelerates the conclusion of his work fairly.
"The White House is committed to fully co-operating with Mr Mueller."
Earlier on Thursday, the US Senate introduced two separate cross-party bills designed to limit the Trump administration's ability to fire Mr Mueller.
The measures were submitted amid concern the president might dismiss Mr Mueller, as he fired former FBI director James Comey in May, citing the Russia inquiry in his decision."""
def wordcount(str):
	# 前期处理
	word_list = str.lower().split(' ')
	# 定义字典接收单词和词频
	word_dict = {}
	for word in word_list:
		if word in word_dict.keys():
			word_dict[word] = word_dict[word] + 1
		else:
			word_dict[word] = 1

	# 按照词频降序排列
	count_list = sorted(word_dict.items(), key=lambda x: x[1], reverse=True)
	for i in count_list:
		print(i)
	return count_list

print(wordcount(context))

  

('the', 31)
('a', 16)
('to', 14)
('in', 9)
('has', 8)
('is', 8)
('that', 8)
('his', 7)
('of', 7)
('mr', 7)
('and', 6)
('on', 6)
('trump', 5)
('he', 5)
('criminal', 4)
('news', 4)
('president', 4)
('at', 4)
('white', 4)
("it's", 4)
('investigation', 4)
('been', 4)
('it', 4)
('as', 4)
('russia', 4)
('were', 4)
('inquiry', 3)
('with', 3)
('are', 3)
('for', 3)
('said', 3)
('house', 3)
('us', 2)
("mueller's", 2)
('taken', 2)
('step', 2)
('jury', 2)
('over', 2)
('june', 2)
('2016', 2)
('meeting', 2)
('between', 2)
('donald', 2)
("trump's", 2)
('russian', 2)
('any', 2)
('team', 2)
('hillary', 2)
('grand', 2)
('up', 2)
('issue', 2)
('not', 2)
('or', 2)
('also', 2)
('prosecutor', 2)
('legal', 2)
('under', 2)
('deadly', 2)
('special', 2)
('concern', 2)
('looking', 2)
('mueller', 2)
('could', 2)
('be', 2)
('big', 2)
('former', 2)
('our', 2)
('there', 2)
('no', 2)
('we', 2)
('because', 2)
('media', 1)
('reports', 1)
('suggest', 1)
('robert', 1)
('first', 1)
('towards', 1)
('possible', 1)
('charges.\naccording', 1)
('reuters', 1)
('agency,', 1)
('issued', 1)
('subpoenas', 1)
('son', 1)
('lawyer.\nthe', 1)
('poured', 1)
('scorn', 1)
('suggestion', 1)
('colluded', 1)
('kremlin', 1)
('beat', 1)
('clinton.\nin', 1)
('us,', 1)
('juries', 1)
('set', 1)
('consider', 1)
('whether', 1)
('evidence', 1)
('case', 1)
('strong', 1)
('enough', 1)
('indictments', 1)
('trial.', 1)
('they', 1)
('do', 1)
('decide', 1)
('innocence', 1)
('guilt', 1)
('potential', 1)
('defendant.\nthe', 1)
('panel', 1)
('ordinary', 1)
('citizens', 1)
('allows', 1)
('subpoenas,', 1)
('writ,', 1)
('obtain', 1)
('documents', 1)
('compel', 1)
('witness', 1)
('testimony', 1)
('oath.\ntrump:', 1)
('us-russia', 1)
('relations', 1)
("'dangerous", 1)
("low'\nthe", 1)
('trump-russia', 1)
('saga', 1)
('200', 1)
('words\nrussia:', 1)
("'cloud'", 1)
('house\nnow', 1)
('serious\nanthony', 1)
('zurcher,', 1)
('bbc', 1)
('north', 1)
('america', 1)
('reporter\nrobert', 1)
('counsel', 1)
('always', 1)
('administration.', 1)
('now', 1)
('serious', 1)
('business.\nwith', 1)
('convened', 1)
('washington', 1)
('dc,', 1)
('into', 1)
('jr', 1)
('nationals,', 1)
('clear', 1)
('focusing', 1)
("president's", 1)
('inner', 1)
('circle.\nthis', 1)
("shouldn't", 1)
('come', 1)
('huge', 1)
('shock,', 1)
('given', 1)
('staffing', 1)
('veteran', 1)
('prosecutors', 1)
('investigators.', 1)
('is,', 1)
('however,', 1)
('necessary', 1)
('eventually', 1)
('lead', 1)
('indictments.', 1)
('very', 1)
('least', 1)
('sign', 1)
('trail', 1)
('something', 1)
('-', 1)
('expanding', 1)
('scope', 1)
('beyond', 1)
('national', 1)
('security', 1)
('adviser', 1)
('michael', 1)
('flynn', 1)
('questionable', 1)
('lobbying.', 1)
('indicates', 1)
('going', 1)
('go', 1)
('away', 1)
('anytime', 1)
('soon.\nin', 1)
('past,', 1)
('when', 1)
('about', 1)
('revealed,', 1)
('escalated', 1)
('rhetoric', 1)
('dead', 1)
('aim', 1)
('perceived', 1)
('adversaries.', 1)
('pressure', 1)
('being', 1)
('applied', 1)
('president.', 1)
('how', 1)
('will', 1)
('respond?\nat', 1)
('rally', 1)
('huntington,', 1)
('west', 1)
('virginia,', 1)
('thursday', 1)
('evening,', 1)
('allegations', 1)
('"hoax"', 1)
('"demeaning', 1)
('country".\n"the', 1)
('story', 1)
('total', 1)
('fabrication,"', 1)
('said.', 1)
('"it\'s', 1)
('just', 1)
('an', 1)
('excuse', 1)
('greatest', 1)
('loss', 1)
('history', 1)
('american', 1)
('politics,', 1)
("that's", 1)
('all', 1)
('is."\nthe', 1)
('crowd', 1)
('went', 1)
('wild', 1)
('continued:', 1)
('"what', 1)
('should', 1)
("clinton's", 1)
('33,000', 1)
('deleted', 1)
('emails."\n"most', 1)
('people', 1)
('know', 1)
('russians', 1)
('campaign,"', 1)
('added.', 1)
('"there', 1)
('never', 1)
('were.', 1)
("didn't", 1)
('win', 1)
('russia,', 1)
('won', 1)
('you,', 1)
('i', 1)
('can', 1)
('tell', 1)
('you."\nmr', 1)
('high-powered', 1)
('fielding', 1)
('questions', 1)
('was', 1)
('reason', 1)
('believe', 1)
('himself', 1)
('investigation.\nty', 1)
('cobb,', 1)
('lawyer', 1)
('appointed', 1)
('last', 1)
('month', 1)
('counsel,', 1)
('statement:', 1)
('"the', 1)
('favours', 1)
('anything', 1)
('accelerates', 1)
('conclusion', 1)
('work', 1)
('fairly.\n"the', 1)
('committed', 1)
('fully', 1)
('co-operating', 1)
('mueller."\nearlier', 1)
('thursday,', 1)
('senate', 1)
('introduced', 1)
('two', 1)
('separate', 1)
('cross-party', 1)
('bills', 1)
('designed', 1)
('limit', 1)
("administration's", 1)
('ability', 1)
('fire', 1)
('mueller.\nthe', 1)
('measures', 1)
('submitted', 1)
('amid', 1)
('might', 1)
('dismiss', 1)
('mueller,', 1)
('fired', 1)
('fbi', 1)
('director', 1)
('james', 1)
('comey', 1)
('may,', 1)
('citing', 1)
('decision.', 1)

 

推荐阅读