From 9e28e4c7b67c54229df11d355047ac8a88ea1817 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 15 Dec 2019 15:09:13 +0700 Subject: Normalize pathname --- tht/C/Q-2016/bai3.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tht/C/Q-2016/bai3.py (limited to 'tht/C/Q-2016/bai3.py') diff --git a/tht/C/Q-2016/bai3.py b/tht/C/Q-2016/bai3.py new file mode 100644 index 0000000..f4139a9 --- /dev/null +++ b/tht/C/Q-2016/bai3.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +d = dict() +with open('bai3.inp') as f: + for i in f.readlines(): + for j in '.,;!?': + i = i.replace(j, ' ') + for j in i.split(): + d[j] = d.get(j, 0) + 1 +l = [(value, key) for (key, value) in d.items()] +l.sort(reverse=True) +with open('bai3.out', 'w') as f: + f.write(str(len(l)) + '\n') + for i, j in l: + f.write('{} {}\n'.format(i, j)) -- cgit 1.4.1