Created
February 14, 2014 15:32
-
-
Save Natim/9003046 to your computer and use it in GitHub Desktop.
Faster count uniq cut file (for flake8 or log for instance) (Thx @boblefrag for http://snippet.gabory.fr/snippet/9/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://snippet.gabory.fr/snippet/9/ | |
# Similar to `cut -d ":" -f 1 | sort | uniq -c | sort -n` | |
# | |
# Usage: flake8 venv | python cutfdu.py | |
# Mock : flake8 venv | cut -d ":" -f 1 | sort | uniq -c | sort -n | |
# | |
# From Natim with love (2014-02-14) | |
import itertools | |
import sys | |
print "\n".join([" %s\t%s" % (elem[1], elem[0]) for elem in sorted( | |
[(test[0], len( | |
[a for a in test[1]] | |
) | |
) for test in itertools.groupby( | |
sorted( | |
[ | |
line.split(":")[0] for line in | |
sys.stdin.readlines() | |
] | |
), | |
lambda x: x) | |
], | |
lambda a, b: a[1] - b[1] | |
)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment