Vertex Colors index access ("mapping" from ob.data.vertices index)...

Hello everyone,
I’m sorry I’m bothering you again with a problem regarding Vertex Colors, but I can’t solve this one :frowning:

I’m using Blender 2.68, I have to set the Vertex Colors of the vertices with a value calculated upon vertices’ coordinates (it is not a “z depth”-like problem, it is something different, let’s just say the vertex color is the output of a function based on the coordinate); I have to do this in a for loop, so I can get the coordinates of the n vertex with: “ob.data.vertices[n].co”,
then I can calculate the color…

… the problem arises when I want to set this (vertex) color: it looks like that the only way to access vertex_colors data is:
“ob.data.vertex_colors[0].data[index].color”,
BUT the index here is not “n” (the index of the vertex).

For example, if we add a Suzanne mesh, switch to Edit Mode, Triangulate it, and then we write:
print(len(ob.data.vertices))
we get 507 vertices.
The object has 968 faces (triangles).

Now, if you write, for example, ob.data.vertices[100].co, you can get/set the coordinates for the vertex at index 100.

I’d like, now, to set the color of that vertex, BUT there’s no “ob.data.vertices[100].color”; now, if we create a vertex_color layer for the object, and then we write:
print(len(ob.data.vertex_colors[0].data))
we get 2904, which is 968 (faces) * 3 (vertices in a triangle face)

I can’t a find a way to “map” the indices in ob.data.vertices on ob.data.vertex_colors.

As I said before, I’d like to do something like this:
ob.data.vertex_colors[0].data[VERTEX_ID_HERE] = my_silly_function(ob.data.vertices[VERTEX_ID_HERE].co)

… how can I do this ( = get the vertex id of a vertex color index)?

Thank you very much in advance.

— Francesco