Looping through dict elements in python -


this question has answer here:

i have piece of json converted dict using json function. this:

{     "imageids": [         {             "imagetag": "1.2",             "imagedigest": "sha256:8b67b1691b29e27a5ccbd6fea5c97c951a025ccd45b26d4c24567ca3c4c0f13b"         },         {             "imagetag": "1.0",             "imagedigest": "sha256:aa52a12bd6e516659452af5b9ed0fad8659f9e0cea6a986c6bfe02af388df189"         }     ] } 

to this:

>>> print data {u'imageids': [{u'imagetag': u'1.2', u'imagedigest': u'sha256:8b67b1691b29e27a5ccbd6fea5c97c951a025ccd45b26d4c24567ca3c4c0f13b'}, {u'imagetag': u'1.0', u'imagedigest': u'sha256:aa52a12bd6e516659452af5b9ed0fad8659f9e0cea6a986c6bfe02af388df189'}]} 

in example number of keys (imageids) fixed there amount of imagetags under imageids.

what i'm trying loop through 'imagetag' elements read tag number , perform operation. if wanted loop through key seems straightforward simple like:

for key in data:     print key, 'corresponds to', data[key] 

however i'm uncertain on how loop through items under key. want achieve print out:

1.2 1.0 

iterate on inner dict same way outer one:

for key, value in data.iteritems():      #now value can dictionary      #for innerkey, innervalues in value[0].iteritems():     #     print innerkey, innervalues      #in order print elements have imagetag key, do:     print value[0]['imagetag'] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -