第九次作业

>>> fo=open('test.txt','w')
>>> fo.write('''I'm a big big girl
  in a big big world
  It's not a big big thing if you leave me
  but I do do feel
  that I too too will miss you much
  miss you much...
  I can see the first leaf falling
  it's all yellow and nice
  It's so very cold outside
  like the way I'm feeling inside
  I'm a big big girl
  in a big big world
  It's not a big big thing if you leave me
  but I do do feel
  that I too too will miss you much
  miss you much...
  Outside it's now raining
  and tears are falling from my eyes
  why did it have to happen
  why did it all have to end
  I'm a big big girl
  in a big big world
  It's not a big big thing if you leave me
  but I do do feel
  that I too too will miss you much
  miss you much...
  I have your arms around me ooooh like fire
  but when I open my eyes
  you're gone...
  I'm a big big girl
  in a big big world
  It's not a big big thing if you leave me
  but I do do feel
  that I too too will miss you much
  miss you much...
  I'm a big big girl
  in a big big world
  It's not a big big thing if you leave me
  but I do feel I will miss you much
  miss you much...''')
1107
>>> fo.close()

fo=open('test.txt','r')
a = fo.read()
exc={'that','a','I','in'}
a = a.lower()
for i in ',...':
    a=a.replace(i,' ')
words=a.split(' ')
#print(words)

dic={}
keys = set(words)
keys=keys-exc
#print(keys)

for i in keys:
    dic[i]=words.count(i)
#print(dic)

b=list(dic.items())
b.sort(key = lambda x:x[1],reverse=true)
#print(b)

for i in range(20):
    print(b[i])
fo.close

 

posted @ 2017-09-26 20:13  037吴宜珊  阅读(204)  评论(0)    收藏  举报