Python implementation of the stable marriage algorithm