字典嵌套列表的格式列表

我正在尝试格式化我需要的数据结构。我要从字典列表中创建字典列表:

[
    {
        "nameWithOwner": "Repository-Org/documentation",
        "languages": {
            "edges": [
                {
                    "node": {
                        "name": "HCL"
                    },
                    "size": 3366
                },
                {
                    "node": {
                        "name": "Shell"
                    },
                    "size": 1435
                },
                {
                    "node": {
                        "name": "Ruby"
                    },
                    "size": 868
                },
                {
                    "node": {
                        "name": "HTML"
                    },
                    "size": 30650
                },
                {
                    "node": {
                        "name": "CSS"
                    },
                    "size": 59692
                }
            ]
        }
    },
    {
        "nameWithOwner": "Repository-Org/integration-api",
        "languages": {
            "edges": [
                {
                    "node": {
                        "name": "JavaScript"
                    },
                    "size": 245648
                },
                {
                    "node": {
                        "name": "Python"
                    },
                    "size": 7483
                },
                {
                    "node": {
                        "name": "Shell"
                    },
                    "size": 20050
                },
                {
                    "node": {
                        "name": "Dockerfile"
                    },
                    "size": 1343
                },
                {
                    "node": {
                        "name": "Roff"
                    },
                    "size": 492
                }
            ]
        }
    }
        {
        "nameWithOwner": "Repository-Org/demo",
        "languages": {
            "edges": [
                {
                    "node": {
                        "name": "Jupyter Notebook"
                    },
                    "size": 5125
                },
                {
                    "node": {
                        "name": "Python"
                    },
                    "size": 8623
                }
            ]
        }
    },
    {
        "nameWithOwner": "Repository-Org/github-link",
        "languages": {
            "edges": []
        }
    },
    {
        "nameWithOwner": "Repository-Org/intelligence-config",
        "languages": {
            "edges": []
        }
    }
]

我想查看并格式化它以获取像这样的字典列表,但我没有找到访问嵌套数据或了解是否有可能的方法

 [
    {
        "name": "Repository-Org/documentation",
        "language": {
            "HCL": 3366,
            "Shell": 1435,
            "Ruby": 868,
            "HTML": 30650,
            "CSS": 59692
        }
    },
    {
        "name": "Repository-Org/integration-api",
        "language": {
            "JavaScript": 245648,
            "Python": 7483,
            "Shell": 20050,
            "Dockerfile": 1343,
            "Roff": 492
        }
    },
    {
        "name": "Repository-Org/demo",
        "language": {
            "Jupyter Notebook": 5125,
            "Python": 8623
        }
    },
    {
        "name": "Repository-Org/github-link",
        "language": {}
    },
    {
        "name": "Repository-Org/intelligence-config",
        "language": {}
    },
]

此刻我做到了:

dicta = {}
array = []
for repository in variables:
    for key,value in repository.items() :
        dicta[key]=value
    array.append(dicta)
    print(array)

并得到了这个结果:

[
    {'nameWithOwner': 'Repository-Org/documentation', 'languages': {'edges': [
                {'node': {'name': 'HCL'
                    }, 'size': 3366
                },
                {'node': {'name': 'Shell'
                    }, 'size': 1435
                },
                {'node': {'name': 'Ruby'
                    }, 'size': 868
                },
                {'node': {'name': 'HTML'
                    }, 'size': 30650
                },
                {'node': {'name': 'CSS'
                    }, 'size': 59692
                }
            ]
        }
    }
]
[
    {'nameWithOwner': 'Repository-Org/integration-api', 'languages': {'edges': [
                {'node': {'name': 'JavaScript'
                    }, 'size': 245648
                },
                {'node': {'name': 'Python'
                    }, 'size': 7483
                },
                {'node': {'name': 'Shell'
                    }, 'size': 20050
                },
                {'node': {'name': 'Dockerfile'
                    }, 'size': 1343
                },
                {'node': {'name': 'Roff'
                    }, 'size': 492
                }
            ]
        }
    },
    {'nameWithOwner': 'Repository-Org/integration-api', 'languages': {'edges': [
                {'node': {'name': 'JavaScript'
                    }, 'size': 245648
                },
                {'node': {'name': 'Python'
                    }, 'size': 7483
                },
                {'node': {'name': 'Shell'
                    }, 'size': 20050
                },
                {'node': {'name': 'Dockerfile'
                    }, 'size': 1343
                },
                {'node': {'name': 'Roff'
                    }, 'size': 492
                }
            ]
        }
    }
]
[
    {'nameWithOwner': 'Repository-Org/demo', 'languages': {'edges': [
                {'node': {'name': 'Jupyter Notebook'
                    }, 'size': 5125
                },
                {'node': {'name': 'Python'
                    }, 'size': 8623
                }
            ]
        }
    },
    {'nameWithOwner': 'Repository-Org/demo', 'languages': {'edges': [
                {'node': {'name': 'Jupyter Notebook'
                    }, 'size': 5125
                },
                {'node': {'name': 'Python'
                    }, 'size': 8623
                }
            ]
        }
    },
    {'nameWithOwner': 'Repository-Org/demo', 'languages': {'edges': [
                {'node': {'name': 'Jupyter Notebook'
                    }, 'size': 5125
                },
                {'node': {'name': 'Python'
                    }, 'size': 8623
                }
            ]
        }
    }
]
[
    {'nameWithOwner': 'Repository-Org/github-link', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/github-link', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/github-link', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/github-link', 'languages': {'edges': []
        }
    }
]
[
    {'nameWithOwner': 'Repository-Org/intelligence-config', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/intelligence-config', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/intelligence-config', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/intelligence-config', 'languages': {'edges': []
        }
    },
    {'nameWithOwner': 'Repository-Org/intelligence-config', 'languages': {'edges': []
        }
    }
]

我应该怎样改变才能得到我想要的东西?

You can find a working example here : https://repl.it/repls/FastAlphanumericKnowledge

评论