【发布时间】:2021-05-20 09:47:09
【问题描述】:
如何从字典中的列表中获取所有值?我需要为每个项目获取标题。
{'results': [{'id': 654959, 'title': 'Pasta With Tuna', 'image': 'https://spoonacular.com/recipeImages/654959-312x231.jpg', 'imageType': 'jpg'}, {'id': 511728, 'title': 'Pasta Margherita', 'image': 'https://spoonacular.com/recipeImages/511728-312x231.jpg', 'imageType': 'jpg'}, {'id': 654812, 'title': 'Pasta and Seafood', 'image': 'https://spoonacular.com/recipeImages/654812-312x231.jpg', 'imageType': 'jpg'}, {'id': 654857, 'title': 'Pasta On The Border', 'image': 'https://spoonacular.com/recipeImages/654857-312x231.jpg', 'imageType': 'jpg'}, {'id': 654883, 'title': 'Pasta Vegetable Soup', 'image': 'https://spoonacular.com/recipeImages/654883-312x231.jpg', 'imageType': 'jpg'}, {'id': 654928, 'title': 'Pasta With Italian Sausage', 'image': 'https://spoonacular.com/recipeImages/654928-312x231.jpg', 'imageType': 'jpg'}, {'id': 654926, 'title': 'Pasta With Gorgonzola Sauce', 'image': 'https://spoonacular.com/recipeImages/654926-312x231.jpg', 'imageType': 'jpg'}, {'id': 654944, 'title': 'Pasta With Salmon Cream Sauce', 'image': 'https://spoonacular.com/recipeImages/654944-312x231.jpg', 'imageType': 'jpg'}, {'id': 654905, 'title': 'Pasta With Chickpeas and Kale', 'image': 'https://spoonacular.com/recipeImages/654905-312x231.jpg', 'imageType': 'jpg'}, {'id': 654901, 'title': 'Pasta With Chicken and Broccoli', 'image': 'https://spoonacular.com/recipeImages/654901-312x231.jpg', 'imageType': 'jpg'}], 'offset': 0, 'number': 10, 'totalResults': 210}
【问题讨论】:
-
您能否更清楚地了解您遇到的问题以及您想要的输出...标题列表?以 id 为键、标题为值的新字典?
-
从 .. 开始。您尝试过简单的 for 循环吗?可能不是最干净的外观和/或最有效的,但仍然是一个开始......到目前为止你尝试过什么?
-
我只是想获取每个“标题”的列表
标签: python api dictionary flask