diff options
| author | 冯昶 <seaker@qq.com> | 2020-10-12 14:30:54 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-10-12 14:30:54 +0800 |
| commit | 838bf861ca973dddaa62662226b4d11c687fcb9a (patch) | |
| tree | 68987cf0f5b2ec85c633475f632ac95858be7969 /challenge-081/walt-mankowski/python/ch-2.py | |
| parent | f0a88ea2365d8ae7dfb90c969d83368a18b53f9a (diff) | |
| parent | 2e7fb5ec844f60c121ef26d50e6b7f24b8849780 (diff) | |
| download | perlweeklychallenge-club-838bf861ca973dddaa62662226b4d11c687fcb9a.tar.gz perlweeklychallenge-club-838bf861ca973dddaa62662226b4d11c687fcb9a.tar.bz2 perlweeklychallenge-club-838bf861ca973dddaa62662226b4d11c687fcb9a.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-081/walt-mankowski/python/ch-2.py')
| -rw-r--r-- | challenge-081/walt-mankowski/python/ch-2.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-081/walt-mankowski/python/ch-2.py b/challenge-081/walt-mankowski/python/ch-2.py new file mode 100644 index 0000000000..b348f03819 --- /dev/null +++ b/challenge-081/walt-mankowski/python/ch-2.py @@ -0,0 +1,27 @@ +from sys import argv +from collections import defaultdict +import re + +d = defaultdict(int) +fname = argv[1] +with open(fname) as f: + for line in f: + line = line.rstrip() + line = re.sub('--', ' ', line) + toks = line.split() + for tok in toks: + tok = re.sub('[."(),]', '', tok); + tok = re.sub("'s$", '', tok) + d[tok] += 1 + +last = 0 +for k in sorted(d, key=lambda k:(d[k], k)): + if d[k] != last: + if last != 0: + print() + print(d[k], end='') + last = d[k] + print(f" {k}", end = '') + +print() + |
