How to connect two pipes in the same position into one

I have some vertical pipes, that are in the same horizontal position, but not at the same level. I can move the endpoint to connect them in Revit, so how to do this with dynamo or a script?
001