关于字典:
dic.kesy() 获取key
dic.values() 获取value
recommendations改进:
persons=prefs.keys() for person in persons: prefs[person]['checked']=0 sims={} for person1 in persons: prefs[person1]['checked']=1 for person2 in persons: if prefs[person2]['checked']==1:continue #if person1==person2: continue
1 利用keys()函数自动获取所有字典的键值(用户的名称)
2 添加字典项checked检查是否已经比较,消除重复比较,字典项要用字符类型,加引号
3 checked标记同样会限制相同项的比较
4 raw_input()可用于调试程序,暂停
5 字典类型 dict
6 items() 获取dict的元素并可以赋值给两个不同的变量 [ (total / simSums[item] ,item) for item,total in totals.items()]
7 将tuple加入list中,可对list排序
8 from ...... import *
9 两本书相似不一定推荐,评分高才推荐
10 topMatches 有共同爱好的人
recommendations 推荐的电影
topatches是相似的电影
recommendations 推荐的人,只是对这一部电影感兴趣,不一定其他方面也相似
11 import 。。。 之后调用函数需要加 modul name。function
from modul import function 后,可以直接写function调用