You can do it like this:
1. Before creating the constraints, create a dictionary that maps variable names to indices:
name2idx = { n : j for j, n in enumerate(model.variables.get_names()) }
2. Then, when creating constraints, use this dictionary to map names to indices:
model.linear_constraints.add(lin_expr = [cplex.SparsePair(ind = [name2idx[y[i][j]] for j in range(len(y[i]))],
val = [1.0 for j in range(len(y[i]))]) for i in range(len(y))],
senses = ["E"] * len(y),
rhs = [1 for i in range(len(y))])
#CPLEXOptimizers#DecisionOptimization