**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由一个错字或一个无法再复制的问题引起的。虽然类似的问题可能是on-topic在这里,但这个问题的解决方式不太可能帮助未来的读者。
3天前关闭。
Improve this question
我一直得到这个错误,并尝试了几件事,但它从来没有真正来到任何东西。我试图删除分裂,并得到同样的错误。
AttributeError Traceback (most recent call last)
<ipython-input-6-aab9e5b0ddb4> in <cell line: 11>()
9 grades = grades.split(",") # split the string by commas to get a list of grades
10 grades_dict = {"A": 4, "B": 3, "C": 2, "D": 1, "F": 0}
---> 11 grades = [grades_dict[grade.strip()] for grade in grades.split(",")]
12 # Step 2: Create the decision matrix
13
AttributeError: 'list' object has no attribute 'split'
我该怎么解决这个问题?
2条答案
按热度按时间zvokhttg1#
在第9行,将名称
grades
赋给.split()
函数的结果,该函数返回一个列表。因此,grades
现在是一个列表。因此,当您尝试在第11行执行
grades.split()
时,您会得到一个错误,因为您显然认为grades
仍然是一个字符串。vltsax252#
你的成绩已经在第9行交了。所以,你不必再分开了。
结果