def process_students(r):
'''r is an open reader with no data about students: their name, cdf account, age, college and
home city. Each line has the following format:
name, cdf, age, college, city.
there are no commas other than the ones used as separators.
Return a dictionary in which each key is a college and its value is the list of cdf accounts
for students at that college'''
我对如何处理这个问题感到困惑。我正在做这个练习测试,这是问题之一。我从创建一个新字典开始。接下来我该怎么做?
d = {}
for line in r:
line.strip()
当我们从文本文件中取出行时,我们是否总是需要剥离它?
问题的 b 部分也令人困惑。它告诉我们编写一个程序,以上述格式打开一个名为“students.txt”的文件,调用我们的函数来构建字典,并将字典腌制到一个名为“students.pck”的文件中。我们可以假设cpickle
已经被导入并且该函数process_students
已经被定义。
我不知道泡菜是什么。但是我什至无法完成第一个,所以我不知道如何继续进行第二个。