How can I make this work for bones instead of vertices?

                bone = bpy.data.objects['bone']
                    
                ob = bpy.context.object
                
                ob.update_from_editmode()
                me = bone.data
                
                
                verts_sel = [v.co for v in me.vertices if v.select]
                pivot = sum(verts_sel, Vector()) / len(verts_sel)
    #                    
                c_location = bpy.context.scene.cursor.location
    #                    
                m_location = bone.matrix_world @ pivot

    #          #get get the offset
                l = c_location - m_location

    #          #split the tuple
                x = l[0]
                y = l[1]
                z = l[2]

well i suggest you just need bone head location

                bone = bpy.data.objects['Armature']

                ob = bpy.context.object

                ob.update_from_editmode()

                me = bone.data

                # get bone head location relative to armature and only if bone is selected
                verts_sel = [v.head_local for v in me.bones if v.select]

                pivot = sum(verts_sel, Vector()) / len(verts_sel)

                c_location = bpy.context.scene.cursor.location

                m_location = bone.matrix_world @ pivot

                # get get the offset
                l = c_location - m_location

                # split the tuple with destructuring assignment
                x, y, x = tuple(l)