如何保存包含多个列表的for循环输出,这些列表是我在python中使用函数做出的API调用的各种响应?
我正在使用API使用多个输入来收集数据。我使用for循环来通过我已经声明的输入值迭代来做出多个API请求。 API调用是使用用户定义的函数进行的。 这里响应_1是API调用的输入。
for auto_sort in response_1:
countryname= auto_sort['Country']
iso=auto_sort['ThreeLetterSymbol']
response_3= api_call(countryname,iso)
我将功能输出作为单词列表,并在每次迭代中列出。
我想单独保存每个迭代输出,或将所有迭代(列表)组合到一个列表中。
需要帮助弄清楚如何完成或基本上如何处理在这种情况下的功能输出。我能够访问最新的迭代
I am using an api to collect data using multiple inputs. I used a for loop to make multiple api requests by iterating through the input values that i already declared . The api call was made using a user defined function.
Here response_1 is the inputs of the api call.
for auto_sort in response_1:
countryname= auto_sort['Country']
iso=auto_sort['ThreeLetterSymbol']
response_3= api_call(countryname,iso)
I am getting the function output as a list of dictionary with each iteration.
I want to save each iteration output individually or combine all the iterations (lists) into one list.
Need help figuring out how this can be done or basically how can i handle the function output in this case. I am able to access the most recent iteration
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你快到了。只需使用列表,在每次迭代中,将API调用的响应附加到该列表中。
示例代码:
You are almost there. Just use a list and in each iteration append the response of the api call to that list.
Example code: