uwc: python version
authorRichard Kojedzinszky <krichy@cflinux.hu>
Fri, 26 Sep 2014 07:32:28 +0000 (09:32 +0200)
committerRichard Kojedzinszky <krichy@cflinux.hu>
Fri, 26 Sep 2014 07:32:28 +0000 (09:32 +0200)
uwc.py [new file with mode: 0644]

diff --git a/uwc.py b/uwc.py
new file mode 100644 (file)
index 0000000..5367cba
--- /dev/null
+++ b/uwc.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+
+import re
+import sys
+
+counts = {}
+word_re = re.compile(r"([a-z']+)", re.IGNORECASE)
+for line in sys.stdin:
+    for w in word_re.findall(line):
+        counts[w] = counts.get(w, 0) + 1
+
+
+words = sorted(counts, key=lambda x: counts[x])
+for w in words:
+    print w