aboutsummaryrefslogtreecommitdiff
path: root/challenge-081/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2020-10-05 13:50:09 +0100
committerRoger Bell_West <roger@firedrake.org>2020-10-05 13:50:09 +0100
commitf7f12eee1c19eda34d5e3f7f0455921b965ccd5c (patch)
tree255a3ec45ba3f30cb0bd139b5f5fc14462cf51cb /challenge-081/roger-bell-west/python/ch-2.py
parentcef248ba491398a30061ba49fbc2a824116ae996 (diff)
downloadperlweeklychallenge-club-f7f12eee1c19eda34d5e3f7f0455921b965ccd5c.tar.gz
perlweeklychallenge-club-f7f12eee1c19eda34d5e3f7f0455921b965ccd5c.tar.bz2
perlweeklychallenge-club-f7f12eee1c19eda34d5e3f7f0455921b965ccd5c.zip
Solutions for challenge #81.
Diffstat (limited to 'challenge-081/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-081/roger-bell-west/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-081/roger-bell-west/python/ch-2.py b/challenge-081/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..eca8fb3cc3
--- /dev/null
+++ b/challenge-081/roger-bell-west/python/ch-2.py
@@ -0,0 +1,23 @@
+#! /usr/bin/python3
+
+import fileinput
+from itertools import chain
+
+c=dict()
+
+for line in fileinput.input():
+ line=line.rstrip("\r\n")
+ for rep in ('--',"'s",'.','"','(',')',','):
+ line=line.replace(rep,' ')
+ for word in line.split():
+ c.setdefault(word,0)
+ c[word] += 1
+
+f=dict()
+for w in sorted(c.keys()):
+ f.setdefault(c[w],list())
+ f[c[w]].append(w)
+
+for n in sorted(f.keys()):
+ print(' '.join((list(str(n)) + f[n])))
+ print('')