object of type NoneType has no len

后端 未结 2 1866
夕颜
夕颜 2021-01-16 01:22
def medianeven (L):
    while len(L) > 2:
        L = L[1:(len(L)-1)]
    return average (L)

def medianodd (L):
    while len(L) > 1:
        L = L[1:(len(L)-         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-16 02:09

    The sort() method call you have in the line:

    new = L.sort();
    

    doesn't return anything. Thus 'new' holds 'None', which has no length. I believe doing L.sort() will sort the list in place. Don't need to store it in 'new'.

提交回复
热议问题