Keeping access to Vertices after deleting some other I'm working on a script that, at some point, gather some vertices index and access by storing them in an array but also delete some other vertices.

I know from what I understood that performing a delete operation format the vertices's index thus making the array I made irrelevant. 

So my question is : How do I keep a way to access those vertices clean and up to date after deleting some other vertices ?

Also, my array order is important, so vertex 0 in my first array have to be vertex 0 in my final array.

Any help is welcome.
Mesh data layers

Instead of storing in an array could use an int data layer on the vertices.

Setting it up, object mode script.

import bpy
import bmesh

context = bpy.context
obj = context.object
me = obj.data

bm = bmesh.new()
bm.from_mesh(me)
int_layer = bm.verts.layers.int

# custom int property on vert
selectionlayer = (int_layer.get("Selection")
        or int_layer.new("Selection"))

# assign verts indices to layer
for v in bm.verts:
    v[selectionlayer] = v.index

bm.to_mesh(me)
me.update()


Ok now each vertex has an integer in the layer that matches the index it once had.

To test.. 

Here is an edit mode script to test, remove some verts and run script

import bpy
import bmesh

context = bpy.context
obj = context.edit_object
me = obj.data

bm = bmesh.from_edit_mesh(me)

int_layer = bm.verts.layers.int

selectionlayer = int_layer.get("Selection")

if selectionlayer:

    print([(v.index, v[selectionlayer]) for v in bm.verts])



After removing vert from default cube and running test script, I get [(0, 0), (1, 1), (2, 2), (3, 3), (4, 5), (5, 6), (6, 7)] so it would appear I have deleted vertex previously known as "4"