我正在使用cachetools中的LRUCache以dict的形式存储一些数据,我很难理解缺少工厂概念的行为,有人能帮忙吗?你知道吗
GivenQuestionsCache=LRUCache(maxsize=100,missing=getGivenQuestions)
def getGivenQuestions(studentId):
cur=db.cursor()
cur.execute(*query*)
questions={}
for each in cur.fetchall():
if(int(each[1]) in questions):
questions[int(each[1])].append([each[3],each[4]])
else:
questions[int(each[1])]=[[each[3],each[4]]]
return questions
现在,当我
print(GivenQuestionsCache[studentId])
我想是这样的
[[211736, None], [211736, 'a'], [207113, 'a'], [219556, None], [207095, None], [89027, None], [89027, None]]
但它会打印出来
{1: [[211736, None], [211736, 'a'], [207113, 'a'], [219556, None], [207095, None], [89027, None], [89027, None]]}
为什么它也会和值一起打印? 另外,由于这个原因,我不能像这样使用append
GivenQuestionsCache[studentId].append([int(questionId),None])
显然是嵌套dict的dict引起了这个问题,我用
GivenQuestionsCache[studentId][studentId].append([int(questionId),None])
解决了这个问题相关问题 更多 >
编程相关推荐