def precision(recommends, test):
	"""计算准确率

	:param recommends: 给用户的推荐结果{用户 : 该用户的推荐列表}
	:param test: 测试集{用户 : 该用户感兴趣的物品列表}
	:return: 准确率
	"""

	hit = 0
	total = 0
	for user, items in recommends.items():
		rec = set(items)
		tes = set(test[user])
		hit += len(rec & tes)
		total += len(tes)
	
	return hit / (total * 1.0)