Problem adding multiple shape keys with bmesh

I’m trying to figure out how multiple shape keys can be created preferably by using bmesh, while also generating geometry by creating vertices. My goal is to have 10 shape keys and each generated vertex is controlled by just one of the shape keys, essentially assigning each vertex into one of the shape keys, depending on the index of the said vertex.

This was my simplified attempt:

import bpy
import bmesh

# Create mesh.
me ='TestMesh')

# Create object.
ob ='TestObject',me)

# Bmesh.
bm =

# Add default shape key.

# List of shape keys to loop through after creation.
ShapeKeys = []

# Base name for shape keys.
KeyBaseStr = 'Shape'

# Create 20 vertices.
for iVert in range(1,21):
    # Index of shape key to add the vertex to.
    iGroup = (iVert-1) % 10

    # Check if group shape key has already been created.
    if len(ShapeKeys) < (iGroup + 1):
        # Name of new shape key.
        SetName = KeyBaseStr + '_Set_' + str(iVert)
        # Create shape key and append to list.
        # Shorthand for new key.
        sk = ShapeKeys[-1]
        print('created shape key #',len(ShapeKeys))
        # Select existing shape key.
        sk = ShapeKeys[iGroup]
        print('using existing shape key #',iGroup+1)

    # Add vertex.
    bv =[iVert, 0, 1]))
    # Assign vertex coordinates in selected shape key.
    bv[sk] = tuple([0, iVert, 2])

# Bind bmesh to mesh.

# Link object to scene.
scene = bpy.context.scene

# Set as active and selected. = ob = True

However, running the code results in an object with just one shape key rather than 10. All ten still appear to be created, but seem to not get binded to the mesh or the object. Any suggestions appreciated!

A solution suggested on Stack Exchange: