top tag merge in python