How to store slected edges/vertecies and create a dictionary?

Hi,
i tried to store slected edges in a dictionary.
At the moment i use vertex groups but the problem is that the operators seems not to update.
Only the vertecies of the last vertex group is all dictionary keys.

import bpy


dic = {}



obj = bpy.data.objects['test']
for gr in obj.vertex_groups:
   dic[gr.name] = []
   bpy.ops.mesh.select_all(action = 'DESELECT')
   bpy.ops.object.vertex_group_set_active(group = gr.name)
   bpy.ops.object.vertex_group_select()
   for verts in obj.data.vertices:
       if verts.select == True:
           dic[gr.name].append(verts.co)

Tips are welcome.

From the code you’ve written you want dictionary like vertex_group : list of vertices it contains.
For that below code works

import bpy

dic = {}

o = bpy.context.object

#vg_idx = 0
for vg_idx,v_group in enumerate(o.vertex_groups):
    dic[v_group.name] = [ v for v in o.data.vertices if vg_idx in [ vg.group for vg in v.groups ] ]

print(dic.keys())

If you just want to store the selected vertices then this code will suffice.

import bpy

o = bpy.context.object
l = [v for v in o.data.vertices if v.select]
print(l)

If this is not what you want then please explain again with some more detail on what you want so i can help you.
Here’s a reference thread you definitely should check out.