Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- path="/Users/rocke/Desktop/wonderland.txt"
- datafile=open(path,"r")
- outfile=open("/Users/rocke/Desktop/wonderland.txt","w")
- for line in datafile:
- outfile.write(line)
- outfile.close()
- datafile=open("/Users/rocke/Desktop/wonderland.txt","r")
- letterFreqDic={}
- alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- for letter in alphabet:
- letterFreqDic[letter]=0
- #print(letterFreqDic)
- n = 0
- for i, line in enumerate(datafile):
- if i< 60000:
- line=line.strip()
- if i <20:print(line)
- for letter in line:
- if letter.isalpha():
- letter = letter.upper()
- #print(letter)
- letterFreqDic[letter] = letterFreqDic[letter]+1
- n+=1
- print(letterFreqDic)
- letterfrequency=[]
- for letter in alphabet:
- c=letterFreqDic[letter]
- letterfrequency.append((c/n,letter))
- letterfrequency.sort()
- letterfrequency.reverse()
- for i in letterfrequency:
- print(i)
- #Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll
- #This eBook is for the use of anyone anywhere at no cost and with
- #almost no restrictions whatsoever. You may copy it, give it away or
- #re-use it under the terms of the Project Gutenberg License included
- #with this eBook or online at www.gutenberg.org
- #Title: Alice's Adventures in Wonderland
- #Author: Lewis Carroll
- #Posting Date: June 25, 2008 [EBook #11]
- #Release Date: March, 1994
- #[Last updated: December 20, 2011]
- #Language: English
- #*** START OF THIS PROJECT GUTENBERG EBOOK ALICE'S ADVENTURES IN WONDERLAND ***
- #{'P': 1968, 'Z': 80, 'S': 7268, 'M': 2467, 'N': 8051, 'Q': 220, 'F': 2382, 'V': 963, 'W': 2952, 'C': 3000, 'T': 12200, 'B': 1746, 'K': #1290, 'E': 15395, 'A': 9802, 'Y': 2584, 'G': 2943, 'J': 235, 'L': 5211, 'I': 8633, 'R': 6610, 'X': 176, 'D': 5469, 'O': 9477, 'H': #7889, 'U': 3978}
- #(0.12517379603053932, 'E')
- #(0.09919586304466253, 'T')
- #(0.07969818439047395, 'A')
- #(0.0770556716454317, 'O')
- #(0.07019326931676817, 'I')
- #(0.06546113880103098, 'N')
- #(0.06414394783273301, 'H')
- #(0.05909471578759076, 'S')
- #(0.05374464382993601, 'R')
- #(0.04446739139272618, 'D')
- #(0.042369642813584955, 'L')
- #(0.03234435599931701, 'U')
- #(0.024392425338851442, 'C')
- #(0.02400214653342982, 'W')
- #(0.023928969257413266, 'G')
- #(0.021010009025197375, 'Y')
- #(0.02005870443698217, 'M')
- #(0.019367585719048046, 'F')
- #(0.016001431022286548, 'P')
- #(0.01419639154721154, 'B')
- #(0.01048874289570612, 'K')
- #(0.007829968533771313, 'V')
- #(0.0019107399848766963, 'J')
- #(0.001788777858182439, 'Q')
- #(0.0014310222865459514, 'X')
- #(0.0006504646757027052, 'Z')
- #https://drive.google.com/file/d/0By4QogT9U6sTbm5pamhQdFRDcDQ/view?usp=sharing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement