Python implementation of 3-way merge
