You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Python中报错zip argument #2 must support iteration

错误原因

你的bst_build函数内的所有代码都没有正确缩进,Python会认为该函数没有执行逻辑,默认返回None。你后续将返回的None作为zip的第二个参数,而None不属于可迭代对象,因此抛出该错误。

解决步骤

  1. 修正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
  1. 你现有打印代码的format用法也存在问题,字符串内没有占位符的话无法打印出res的内容,修正为:
res = bst_insert()
print("Time is {}".format(res))
# 也可以用更简洁的f-string写法
# print(f"Time is {res}")

内容的提问来源于stack exchange,提问作者Rmd90

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 19:36:05