Created
April 12, 2016 10:41
-
-
Save McSinyx/e4dd863f9a9ff5666ff45c781d9fec04 to your computer and use it in GitHub Desktop.
Bài 3 Tin học trẻ Ba Đình 2015-2016 viết trên Python 3.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment