简体   繁体   English

列表错误后无类型

[英]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 当我通过第二个功能进行编程时,我意识到print(x)给了我:[['Anna',74.0],['Bill',65.0],['Cal',98.0]]无

Due to this none, I am unable to iterate through the list to and set it to L. What is causing this none? 由于没有此限制,因此我无法遍历该列表并将其设置为L。是什么原因引起的? Here is a paste bin of the 3 other functions. 这是其他3个功能的粘贴框。 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? 但是它说我找不到nonetype的len,为什么我的xa none type?

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

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

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