Here’s a Python snippet that selects vertices sharing only two edges (using maya.cmds as mc):
With the mesh object selected,
obj = mc.ls(sl=True)[0]
vertCount = mc.polyEvaluate(obj, v=True)
vertList = ['{0}.vtx[{1}]'.format(obj,vert) for vert in range(vertCount) if len(mc.polyInfo('{0}.vtx[{1}]'.format(obj,vert), ve=1)[0].split(':')[1].split()) == 2]
mc.select(vertList)
The if statement containing the polyInfo command does the filtering by counting the number of edges around the queried vertex. Unfortunately this returns a line of values in a string, so I had to split it a couple times to retrieve the edges count. For example, vertex 302 of ‘polySurface’ is shared by the edges 506, 489, 484, and 485:
mc.polyInfo('polySurface.vtx[302]', ve=1)[0]
# Result: u'VERTEX 302: 506 489 484 485 n' #
UPDATE: A vertex sharing two edges is called ‘winged’. Here’s another way to select winged vertices using PyMEL (as pm)…
obj = pm.ls(sl=True)[0]
vertList = [obj.verts[v] for v in range(len(obj.verts)) if len(obj.verts[v].connectedEdges()) == 2]
pm.select(vertList)