How to unpack key,value pairs in python?

This question already has an answer here:

  • Iterating over dictionaries using 'for' loops 12 answers

  • Like this - first:

    for obj in objArray:
        for key in obj:
            value = obj[key]
            print(key)
            print(value)
    

    Second (python 3):

    for obj in objArray:
        for key, value in obj.items():
               print(key)
               print(value)
    

    For python 2 you can use for key, value in d.iteritems()

    链接地址: http://www.djcxy.com/p/30376.html

    上一篇: 解析嵌套的JSON响应Python

    下一篇: 如何解开python中的键值对?