NameError: free variable 'list' referenced before assignment in enclosing scope

NameError: free variable 'list' referenced before assignment in enclosing scope

我正在尝试编写一个接收列表列表作为输入参数的十进制缩放函数。

def decimal_scale(data):
    #calculate the maximum absolute value for each attribute
    grouped_attributes = [list(attributes) for attributes in zip(*data)]

    #absolute list of list grouped attributes
    absolute_attributes = []
    for item in grouped_attributes:
        list = []
        for i in range(0, len(item)):
            list.append(abs(item[i]))
        absolute_attributes.append(list)

    max_att_val = []
    for abs_att_list in absolute_attributes:
        abs_att_list.sort()
        max_att_val.append(abs_att_list[-1])

        #calculate the appropriate k for each attribute
    k_attributes = []
    for max in max_att_val:
        k = 0
        while max/(10**k) > 1:
            k+=1

        k_attributes.append(k) #appropriate ks for all the Attributes

    res = []
    for item in data:
        res.append([item[i]/(10**(k_attributes[i])) for i in range(0, len(item))])
    return res

当我 运行 这段代码时,我得到 error:

文件 "mynormalize.py",第 39 行,在

grouped_attributes = [list(attributes) for attributes in zip(*data)]

NameError: free variable 'list' referenced before assignment in enclosing scope

有人可以建议解决此问题的方法吗?也许还有更有效的方法?

您正在使用列表 list = [],更改此列表的名称它必须起作用