Efficient way to get selected vertices via python (without iterating over the entire mesh) What's the best/fastest way to construct a list of selected vertices for a mesh object in python?

I want to avoid iterating over every vertex in the mesh if possible, since that seems like a really inefficient/wasteful way to go about it.

There's a nice attribute called select_history in the bmesh module that gives you a list of vertices in the order that they were selected...but of course, it will only give you verts that have been selected manually (not by box or circle select) after the bmesh was initialized.

I've been searching through the edit mesh api for an attribute that will give me an updated list of selected verts (so that I don't have to iterate over the whole mesh). Does such a thing not exist?
You have to iterate over the entire mesh since blender isn't storing this data in a separate list internally.

You can use the following line of code to get a list if selected vertices from a bpy.types.Mesh object ('mesh' in the code):

selected_verts = list(filter(lambda v: v.select, mesh.vertices))


or with list comprehension:

selected_verts = [v for v in mesh.vertices if v.select]


However, in most cases, brute force looping through all the vertices of the mesh should be fine.