Skip to content

Instantly share code, notes, and snippets.

@McSinyx
Created April 12, 2016 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McSinyx/e4dd863f9a9ff5666ff45c781d9fec04 to your computer and use it in GitHub Desktop.
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
#!/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