How to find non manifold edges
Select 1 edge of that type
Shift+G >> Amount of Faces Around an Edge.


When you do this, Blender posts the following action it took in python.





As for the raw bmesh method of detecting this:

You can find the Reference in this Link





For getting the Horizontal &amp; Vertical sets in two separate passes, I would inspect the verts like so:

Horizontal Case:


  All Edges Have the Same Z values for the start and end vertices.


Vertical Case: 


  All Edges Have different Z values for the start and end vertices.