python - if __ and __ in ___ then -


i trying create script loops through list.

i need through finite list (400) of competency identifiers (e.g. 124, 129 etc - normal ints )

i have dictionary records competencies each user has. key user name , value each key list of integers (i.e. competencies users have)

for example

user x - [124, 198, 2244 ...] user y - [129, 254, 198, 2244 ...] 

i looking compile matrix highlighting how each competency occurs every other competency - adjacency matrix.

for example in above examples competency 198 has occurred competency 2244 on 2 occasions. whereas competency 254 , 124 have never occurred together.

i using code:

fe = []     count = 0 competency_matches = 0 comp in competencies_list:     common_competencies = str("") comp2 in competencies_list:     matches = int(0)     person in listx:         if comp , 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 

this doesnt work , returns how many times each competency has occurred overall. think problem "if comp , comp2 in d1[person]:" line.

the problem be, example, if person had following competencies [123, 1299, 1236] , searched competency 123, returned twice due appearing in 123 , 1236 entries. way exist force exact match when using if __ , __ operation.

or have improve suggestion how achieve ...

thanks in advance pointers. cheers

you're misinterpreting how and works. test if 2 values in list, use:

if comp1 in d1[person] , comp2 in d1[person]:   ... 

your version else. binds this: if (comp1) , (comp2 in d1[person]). in other words, interprets comp1 truth value, , boolean and list inclusion check. valid code, doesn't want.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -