Source

woocode / py / hash_key.py

import hashlib
from collections import defaultdict

def hash_obj(s):
    m = hashlib.md5(s)
    return m.hexdigest()

d = defaultdict(dict)

s = 'aaabbccc'
for i in xrange(1000000):
    hash_key = hash_obj(s + str(i))
    head, tail = hash_key[:2], hash_key[2:]
    if head not in d:
        d[head] = {}
    else:
        d[head][tail] = ('a', 'b' + str(i))

raw_input()