[英]How to create a multi-dimensional vector with an unknown number of dimensions using Pyhton?
完全编辑(为简单起见):
我正在尝试自动化一项任务,将链接列表放入字典中,而不是遍历每个链接并获取其各自的链接等等,从而在最后创建一个巨大的树状结构。
我还没有测试这段代码,所以如果出现问题请告诉我
yourlinks={'a':'google.com','b':'google.com'}
def yourawesomefunction(link):
#does some thing
return dictionary of more links!
def loop(dictionary):
if dictionary=={}:
pass
#when your tree finally ends, go on to the next branch
for x in dictionary:
dictionary[x]=yourawesomefunction(dictionary[x])
#create branches
for x in dictionary:
loop(dictionary[x])
#go into next layer
loop(yourlinks)
哦,顺便说一句,我希望你的树在某个时候结束,因为如果没有结束,它可能会永远跟随第一个链接
此外,function 调用自身会导致很多问题,因此请尽可能避免这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.