Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main(filemane):
- with open(filemane, 'r') as f:
- hist = {}
- byte_size= 1024
- while True:
- res = f.read(byte_size)
- if res == '':
- break
- for ch in res:
- if ch in hist:
- hist[ch] += 1
- else:
- hist[ch] = 1
- print('Hist')
- print(hist)
- new_top = 0
- prev_top = 0
- top_key = 0
- for key in hist:
- new_top = max(hist[key],0)
- if prev_top < new_top:
- top_key = key
- prev_top = new_top
- print('Top key {} with occurance {}'.format(top_key, prev_top))
- if __name__ == "__main__":
- filemane = "sample_file.txt"
- main(filemane)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement