繁体   English   中英

Python:TypeError:“ NoneType”对象不可下标

[英]Python: TypeError: 'NoneType' object is not subscriptable

#Uses python3

import sys

def max_dot_product(a,b,n):


    a = a.sort(reverse=True)
    b = b.sort(reverse=True)
    res = 0

    for i in range(n):
        res += a[i]*b[i]
    return res

if __name__ == '__main__':
    data = [int(x) for x in input("").split()]
    n = data[0]
    a = data[1:(n + 1)]
    b = data[(n + 1):]
    print(max_dot_product(a,b,n))

当我运行此代码时,它表明“ TypeError:'NoneType'对象不可下标”。

sort对列表sort排序并(隐式)返回None 删除返回值的分配,您应该可以:

a.sort(reverse=True)
b.sort(reverse=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM