group_names to dictionary

Is there a way to convert an array to a dictionary. I want to use the group names as metadata for os_server or ec2 so I can reference them later using dynamic inventories.