Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myfile = open('secret.txt')
- letters = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
- freq = []
- for i in range(26):
- freq.append(0)
- for line in myfile:
- for ch in line:
- if ch.upper() in letters:
- freq[letters.index(ch.upper())] += 1
- f = open("letterFreqs.txt", "w")
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[0]}:{freq[0]}',f'{letters[1]}:{freq[1]}',f'{letters[2]}:{freq[2]}',f'{letters[3]}:{freq[3]}')))
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[4]}:{freq[4]}',f'{letters[5]}:{freq[5]}',f'{letters[6]}:{freq[6]}',f'{letters[7]}:{freq[7]}')))
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[8]}:{freq[8]}',f'{letters[9]}:{freq[9]}',f'{letters[10]}:{freq[10]}',f'{letters[11]}:{freq[11]}')))
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[12]}:{freq[12]}',f'{letters[13]}:{freq[13]}',f'{letters[14]}:{freq[14]}',f'{letters[15]}:{freq[15]}')))
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[16]}:{freq[16]}',f'{letters[17]}:{freq[17]}',f'{letters[18]}:{freq[18]}',f'{letters[19]}:{freq[19]}')))
- f.write(('{0:7}{1:7}{2:7}{2:7}\n'.format(f'{letters[20]}:{freq[20]}',f'{letters[21]}:{freq[21]}',f'{letters[22]}:{freq[22]}',f'{letters[23]}:{freq[23]}')))
- f.write(('{0:7}{1:7}'.format(f'{letters[24]}:{freq[24]}',f'{letters[25]}:{freq[25]}')))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement