Perfect hash implementation in python