Guest User

Untitled

a guest
Oct 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. '''
  5. Created on 03-09-2011
  6.  
  7. @author: Maciej Czekaj
  8. '''
  9. import string
  10.  
  11.  
  12. def count_chars(file):
  13.     count = {}
  14.     counter = 0
  15.     for i in range(len(file)):
  16.         if file[i] in string.letters:
  17.             if file[i] in count:
  18.                 count[file[i]] += 1
  19.             else:
  20.                 count[file[i]] = 1
  21.             counter += 1
  22.    
  23.     for letter in count:
  24.         count[letter] = float(count[letter]) / counter
  25.     print count
  26.  
  27. def main():
  28.     file = open('pl.txt').read()
  29.     file = file.lower()
  30.     print file
  31.     count_chars(file)
  32.     return 0
  33.  
  34. if __name__ == '__main__':
  35.     main()
Add Comment
Please, Sign In to add comment