我无法理解第二个函数引发的错误。当我正在浏览第二个函数时,我意识到print(x)给了我: [[' Anna',74.0],['比尔',65.0],[' Cal',98.0]] 无
由于没有这个,我无法遍历列表并将其设置为L.什么导致这个没有?这是其他3个功能的粘贴箱。 code here!。非常感谢任何建议或推动正确的方向。
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)
我最后一个函数的代码是:
Say I changed the last function code to:
x = string_avg(L)
for i in range(0,len(x)):
L[i] = x[i][1]
但它说我找不到len的nonetype,为什么我的x是无类型?
答案 0 :(得分:0)
average_grade()
不返回列表,只打印它并返回None