I'm not sure if this is what you are asking for, but that is how I would turn a dictionary into a list using its key as the root value.
new_list = [] dict = {test:1, test:2, test:3} for key, value in dict.iteritems(): new_list.append((key, value))
This is where I am doing something very similar to what you want.
if str(vm_mor) == vm['config.annotation']: annotation= pickle.load(open(str(vm_mor), "rb")) print annotation sql_check_exist = '''select a.vm_mor, b.license_id, c.product from vms a , vm_licenses b, licenses c where a.vm_id = b.vm_id and b.license_id = c.license_id and a.vm_mor = '%s' ''' % str(vm_mor) cursor_exist.execute(sql_check_exist) database_license = [] for vm_mor, license_id, product in cursor_exist: database_license.append((product,license_id)) checklist_database_license = [int(i[1]) for i in database_license]
source share