ionel's codelog

That history meme

Mon 14 April 2008

Python version, shorter than Paddy's version:

$ history|python -c'import sys;c=[i.split()[1] for i in sys.stdin]; [sys.stdout.write("%s %s\n"%x) for x in sorted(set((c.count(i),i) for i in c), key=lambda (a,b):a)[::-1][:10]]'
198 python
71 ab
37 cat
36 /root/python/bin/python
31 cd
21 nc
21 strace
10 echo
9 history
8 easy_install

Still not shorter than the bash version:

$ history|awk '{a[$2]++} END{for(i in a){print a[i]" "i}}'|sort -rn|head

This entry was tagged as python

blog comments powered by Disqus