简体   繁体   中英

NoneType after List Error

I'm having trouble understanding the error raised from the second function. As I was hacking through the second function I realized print(x) gives me: [['Anna', 74.0], ['Bill', 65.0], ['Cal', 98.0]] None

Due to this none, I am unable to iterate through the list to and set it to L. What is causing this none? Here is a paste bin of the 3 other functions. code here! . Any advice or push in the correct direction is greatly appreciated.


def string_avg(L):
'''(list of str) -> list of list
Given a list of strings where each string has the format:
'name, grade, grade, grade, ...' return a new list of 
lists where each inner list has the format :
[name (str), average grade (float)]
Requirement: This function should be 1 line long.

>>> string_avg(['Anna, 50, 92, 80', 'Bill, 60, 70', 'Cal, 98.5, 100, 95.5, 
98'])
[['Anna', 74.0], ['Bill', 65.0], ['Cal', 98.0]]
'''
return(average_grade((string_list(L))))


def string_avg_update(L):
'''(list of str) -> NoneType
Given a list of strings where each string has the format:
'name, grade, grade, grade, ...' update  the given 
list of strs to be a list of floats where each item 
is the average of the corresponding numbers in the 
string. Note this function does NOT RETURN the list.
>>> L = ['Anna, 50, 92, 80', 'Bill, 60, 70', 'Cal, 98.5, 100, 95.5, 98']
>>> string_avg_update(L)
>>> L 
[74.0, 65.0, 98.0]
'''

x = string_avg(L)       

My intended code for the last function is:

Say I changed the last function code to: 
x = string_avg(L)       

for i in range(0,len(x)):
    L[i] = x[i][1] 

But it says I cannot find len of nonetype, why is my xa none type?

average_grade()不返回列表,而是仅打印并返回None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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