如何解决Python中报错zip argument #2 must support iteration
错误原因
你的bst_build函数内的所有代码都没有正确缩进,Python会认为该函数没有执行逻辑,默认返回None。你后续将返回的None作为zip的第二个参数,而None不属于可迭代对象,因此抛出该错误。
解决步骤
- 修正
bst_build函数的缩进,将函数内的所有代码向右缩进4个空格(和bst_insert等其他函数的内部代码缩进对齐即可),修正后的bst_build代码如下:
def bst_build(): #bst_list = importlib.import_module("BST").BinarySearchTree() bst11 = importlib.import_module("BST").BinarySearchTree() bst12 = importlib.import_module("BST").BinarySearchTree() bst13 = importlib.import_module("BST").BinarySearchTree() bst21 = importlib.import_module("BST").BinarySearchTree() bst22 = importlib.import_module("BST").BinarySearchTree() bst23 = importlib.import_module("BST").BinarySearchTree() bst_list = [bst11, bst12, bst13, bst21, bst22, bst23] return bst_list
- 你现有打印代码的
format用法也存在问题,字符串内没有占位符的话无法打印出res的内容,修正为:
res = bst_insert() print("Time is {}".format(res)) # 也可以用更简洁的f-string写法 # print(f"Time is {res}")
内容的提问来源于stack exchange,提问作者Rmd90
相关产品推荐
相关产品推荐

