#!/usr/bin/python # -*- coding: utf-8 -*- """Make my links into a blog. No, fuck this. This takes 250 ms to run and all it’s doing so far is extracting the tags. Fuck Python and fuck your mother. """ import collections import re import sys def main(infile, options): tags = collections.Counter() for line in infile: for tag in re.findall(r' #[-a-zA-Z0-9_]+', line): tags[tag] += 1 for count, tag in sorted((v, k) for k, v in canonicalize(tags)): print tag, count def canonicalize(tags): result = {} for tag, count in tags.items(): tag = tag[2:].lower().replace('-', '') if tag not in result: result[tag] = 0 result[tag] += count return result.items() if __name__ == '__main__': main(sys.stdin, {})