Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import OrderedDict
- def main():
- ord_dict = OrderedDict()
- filename = '285.txt'
- all_chars = 0
- with open(filename, encoding='utf8', errors='ignore') as f:
- while True:
- c = f.read(1).lower()
- if c != ' ':
- counter = ord_dict.get(c, None)
- if counter is None:
- ord_dict[c] = 1
- else:
- ord_dict[c] += 1
- all_chars += 1
- if not c:
- break
- tuples_sorted = sorted(ord_dict.items(), key=lambda x:x[1], reverse=True)
- for x, y in tuples_sorted:
- print(x, round(y / all_chars * 100, 2), "%")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement