projects
/
uwc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
06427ec
)
python version produces the same output
author
Richard Kojedzinszky
<krichy@tvnetwork.hu>
Fri, 26 Sep 2014 07:53:14 +0000
(09:53 +0200)
committer
Richard Kojedzinszky
<krichy@tvnetwork.hu>
Fri, 26 Sep 2014 07:53:14 +0000
(09:53 +0200)
uwc.py
patch
|
blob
|
history
diff --git
a/uwc.py
b/uwc.py
index
5367cba
..
8a79795
100644
(file)
--- a/
uwc.py
+++ b/
uwc.py
@@
-9,7
+9,17
@@
for line in sys.stdin:
for w in word_re.findall(line):
counts[w] = counts.get(w, 0) + 1
+def sorter(a, b):
+ if counts[a] != counts[b]:
+ return counts[a] - counts[b]
-words = sorted(counts, key=lambda x: counts[x])
+ if a < b:
+ return -1
+ if a > b:
+ return 1
+
+ return 0
+
+words = sorted(counts, cmp=sorter)
for w in words:
- print w
+ print w
, counts[w]