How to paint individual vertex via python?

I know how to paint the same color by selecting all in vertex paint mode.
I want to paint different colors by selecting vertices by index in python code.

import bpy
import random
import bmesh

obj = bpy.data.objects[“Cube”]
mesh = obj.data

if not mesh.vertex_colors:
mesh.vertex_colors.new()

color_layer = mesh.vertex_colors[“Col”]

i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
r, g, b = [random.random() for i in range(3)]
color_layer.data[i].color = (0.5, 0.4, 0.3, 1.0)
i += 1
I know how to paint the same color by selecting all in vertex paint mode.
I want to paint different colors by selecting vertices by index

This code is a code that allows you to paint the entire vertex with only one color without selecting each index.
I want to paint this by vertex index