Apply/lock hair particles after hair dynamics simulation?

I came across this thread from a Google search, since I had the exact same problem. I was disappointed to learn there seems to be no build-in feature in Blender for this.
Anyway, some more searching and coding later, I made a script to apply hair dynamics to the static hair particles. I thought I leave it here for others to find/use. It is certainly far from perfect or even optimized, but I hope it helps.

import bpy

# How to use:
# 1. edit hair system (important, move at least one hair, at least a bit to initiate hair editing)
# 2. run hair dynamics
# 3. move to frame where dynamics should be applied
# 4. run script
# 5. if happy, delete cache
# 6. keep editing hair

# get the depsgraph and the evaluated object   
deps_graph = bpy.context.evaluated_depsgraph_get()
evaluated_object = bpy.context.object.evaluated_get(deps_graph)
# assume context object has a particle system (warning, no check), use active
particle_system = evaluated_object.particle_systems.active

# Variable to hold hair-verticies-coordinats
hairs = []

# At current frame
# For each particle (hair)
#   For each vertex
#     Store XYZ coordinates
for p in particle_system.particles:
    hair = []
    for v in p.hair_keys:
        hair.append([v.co[0], v.co[1], v.co[2]])
    hairs.append(hair)

# Deactivate hair dynamics
particle_system.use_hair_dynamics = False

# On static hair system
# For each particle (hair)
#   For each vertex
#     Overwrite XYZ coordinates
for p,hair in zip(particle_system.particles,hairs):
    for v,h in zip(p.hair_keys,hair):
        #print(v.co, h)
        v.co[0] = h[0]
        v.co[1] = h[1]
        v.co[2] = h[2]
        #print(v.co, h)

# Update view and UI
bpy.context.scene.frame_set(bpy.context.scene.frame_current)