Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def main(filemane):
  2. with open(filemane, 'r') as f:
  3. hist = {}
  4. byte_size= 1024
  5. while True:
  6. res = f.read(byte_size)
  7. if res == '':
  8. break
  9. for ch in res:
  10. if ch in hist:
  11. hist[ch] += 1
  12. else:
  13. hist[ch] = 1
  14. print('Hist')
  15. print(hist)
  16. new_top = 0
  17. prev_top = 0
  18. top_key = 0
  19. for key in hist:
  20. new_top = max(hist[key],0)
  21. if prev_top < new_top:
  22. top_key = key
  23. prev_top = new_top
  24.  
  25. print('Top key {} with occurance {}'.format(top_key, prev_top))
  26.  
  27. if __name__ == "__main__":
  28. filemane = "sample_file.txt"
  29. main(filemane)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement