python - Processing of Items from a list -


consider have dictionary named "tenant_id_dict" entry follows:

defaultdict(<type 'list'>, {u'b0116ce25cad4106becbbddfffa61a1c': [u'demo_ins1'], u'1578f81703ec4bbaa1d548532c922ab9': [u'new_ins_1', u'new_tenant_ins']}) 

that combination of tenant_id , instance_name.

now need utilize tenant_id , instance_name needed.

consider following code:

for tenants,instances in tenant_id_dict.iteritems():          compute_value_for_instance = ck.reports.get_total(tenant_id=tenants, service='compute', instance_name=instances)         print compute_value_for_instance 

here need process values tenants , instance_name dynamically.

but in above code unable result correctly instance having list of values.

i need process till last item in list.

someone let me know way processing of values here.

you initialized defaultdit list. list iterable , value each key. need iterate on values (i.e list) below.

for tenants,instances in tenant_id_dict.iteritems():         single_ins in instances:                 compute_value_for_instance = ck.reports.get_total(tenant_id=tenants, service='compute', instance_name=single_ins)                 print compute_value_for_instance 

working demo-

from collections import defaultdict #create dummy defaultdict list values d = defaultdict(list)  in range(5):     d[i].append(i+100)     d[i].append(i+200)     d[i].append(i+300)   #experiment k,v in d.iteritems():     single_vale in v:#here v list         print str(k)+str(single_vale) print d 

output-

0100 0200 0300 1101 1201 1301 2102 2202 2302 3103 3203 3303 4104 4204 4304 defaultdict(<type 'list'>, {0: [100, 200, 300], 1: [101, 201, 301], 2: [102, 202, 302], 3: [103, 203, 303], 4: [104, 204, 304]}) 

Comments