#!/usr/bin/python "hash a list of words so each word has its own unique slot" import sys, os, re, zlib slots, hash = 256, {} list = sys.stdin.readlines() while len(list) > slots: slots <<= 2 slots <<= 2 bitmask = slots - 1 for word in list: hash[word] = zlib.crc32(word) & bitmask reversehash = {} for word in hash.keys(): if reversehash.has_key(hash[word]): reversehash[hash[word]] += word else: reversehash[hash[word]] = word hashes = hash.values() hashes.sort(lambda a, b: cmp(len(reversehash[b]), len(reversehash[a]))) for hashvalue in hashes: print hashvalue, reversehash[hashvalue]