正如标题所示,下面的测试用例可以给予我的任务是什么。假设我有一个json文件:
[
{
"id": "978-0062562",
"name": "The Hidden Oracle",
"author": "Rick Riordan",
"details": [
{
"genre": "Fantasy",
"published_year": 2017,
"publisher": "Disney-Hyperion"
}
,
{
"genre": "Fantasy",
"published_year": 2018,
"publisher": "Disney-Hyperion"
}
]
},
{
"id": "978-148474",
"name": "Magnus Chase and the Gods of Asgard",
"author": "Rick Riordan",
"details": [
{
"genre": "Fantasy",
"published_year": 2016,
"publisher": "Disney-Hyperion"
}
]
}
]
字符串
我的预期输出是:
[('978-0062562', 'The Hidden Oracle', 'Rick Riordan', [('Fantasy', 2017, 'Disney-Hyperion'), ('Fantasy', 2018, 'Disney-Hyperion')]), ('978-148474', 'Magnus Chase and the Gods of Asgard', 'Rick Riordan', [('Fantasy', 2016, 'Disney-Hyperion')])]
型
我想找到一种更通用的方法,它可能适用于任何类似的数据集。我甚至尝试递归地迭代内容以达到某些东西,但失败了。
1条答案
按热度按时间jobtbby31#
下面是递归方法来转换列表:
字符串
印刷品:
型