2 回答
TA贡献1725条经验 获得超7个赞
像这样更改函数
def getDetails():
req = requests.get("url").json()
myDict = {} # Initialize empty dict
for name in req['collections']:
collection_size = requests.get("string url" + name + "/select?q=*:*&rows=0").json()["response"]["numFound"]
myDict[name] = collection_size # add keys as name and value as collection_size, dynamically
return myDict
然后像这样使用它:
myDetails = getDetails()
myDetails 就是字典。
TA贡献1890条经验 获得超9个赞
这是一个非常简单的修改
file_dict = dict()
for name in req['collections']:
collection_size = requests.get("string url" + name + "/select?q=*:*&rows=0").json()["response"]["numFound"]
print(name, collection_size)
file_dict[name] = collection_size
- 2 回答
- 0 关注
- 131 浏览
添加回答
举报