我想创建一个脚本,通过列表循环。如果__和__在___然后
我需要通过能力标识符的有限名单(400)(例如124,129等 - 正常整数)看起来则有
我说什么记录能力每个用户都拥有一本字典。关键是用户名和每个键的值是一个整数列表(即其能力的用户有)
例如
User x - [124, 198, 2244 ...]
User Y - [129, 254, 198, 2244 ...]
我期待编译矩阵突出多久每种能力与所有其他能力一起发生 - 邻接矩阵。
例如在上述示例中,胜任特征198在两次出现时与胜任特征2244发生。而能力254和124从未一起出现。
我目前使用此代码:
fe = []
count = 0
competency_matches = 0
for comp in competencies_list:
common_competencies = str("")
for comp2 in competencies_list:
matches = int(0)
for person in listx:
if comp and comp2 in d1[person]:
matches = matches + 1
else:
matches = matches
common_competencies = str(common_competencies) + str(matches) + ","
fe.append(common_competencies)
print fe
print count
count = count + 1
这不工作,只是返回了多少次每种能力已全面发生了。我认为问题在于“如果在comp1和comp2中,在d1 [person]:”行中。
例如,如果一个人具有以下能力[123,1299,1236],并且我搜索了能力123,则该问题将返回两次,因为这出现在123和1236个条目中。在使用if __和__ then操作时,是否存在强制进行精确匹配的方法。
或者有没有人有一个完善的建议如何实现这一目标?
预先感谢任何指针。欢呼声
common_competencies = str(“”)??? Python不是Java。some_var =''足够好 – 2011-04-11 17:26:33
@RestRisiko:你如何在Java中编写它? – khachik 2011-04-11 17:29:23
不知道 - 但在这里使用str(..)没有意义 – 2011-04-11 17:30:13