第二次作业
一、安装Spark
二、Python编程练习:英文文本的词频统计
def gettext():
txt = open("wenben.txt","r",errors='ignore').read()
txt = txt.lower()
for ch in '!"#$&()*+,-./:;<=>?@[\\]^_{|}·~‘’':
txt = txt.replace(ch,"")
return txt
txt = gettext()
words = txt.split()
counts = {}
for word in words:
counts[word] = counts.get(word,0) + 1
items = list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
word,count = items[i]
print("{0:<10}{1:>5}".format(word,count))