Python3中zip相关语句的等效代码

Python3中zip相关语句的等效代码,python,python-3.x,zip,Python,Python 3.x,Zip,在Python3中,以下代码的等效代码是什么 def spiral_matrix(m): result = [] while len(m) > 0: result += m[0] m = zip(*m[1:len(m)])[::-1] return result 错误是: Traceback (most recent call last): File "<input>", line 1, in <module&

在Python3中,以下代码的等效代码是什么

def spiral_matrix(m):
    result = []
    while len(m) > 0:
        result += m[0]
        m = zip(*m[1:len(m)])[::-1]
    return result
错误是:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/mona/Python_Playground/spiral_matrix.py", line 38, in <module>
    print(spiral_matrix(b))
  File "/Users/mona/Python_Playground/spiral_matrix.py", line 34, in spiral_matrix
    m = zip(*m[1:len(m)])[::-1]
试试这个:

m = list(zip(*m[1:len(m)]))[::-1]

在Python3中,zip返回一个迭代器。将其包装到列表中将运行迭代器来创建列表,给出与Python 2相同的行为。

您错过了实际的错误消息;猜测假设输入可能是什么也没有提供,如果你搜索它,你会得到例如。