title: if __ and __ in ___ then
body: <p>I am trying to create a script that loops through a list.</p>
  
  <p>I need to look through a finite list (400) of competency identifiers (e.g. 124, 129 etc - normal ints )</p>
  
  <p>I then have a dictionary that records what competencies each user has. The Key is the user name and the value for each key is a list of integers (i.e. which competencies the users have)</p>
  
  <p>For example</p>
  
  <pre><code>User x - [124, 198, 2244 ...]
  User Y - [129, 254, 198, 2244 ...]
  </code></pre>
  
  <p>I am looking to compile a matrix highlighting how often each competency occurs with every other competency - an adjacency matrix.</p>
  
  <p>For example in the above examples competency 198 has occurred with competency 2244 on two occasions. Whereas competency 254 and 124 have never occurred together.</p>
  
  <p>I am currently using this code:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>This doesnt work and simply returns how many times each competency has occurred overall. I think the problem is with the "if comp and comp2 in d1[person]:" line. </p>
  
  <p>The problem would be, for example, if a person had the following competencies [123, 1299, 1236] and I searched for competency 123, this would be returned twice due to this appearing in the 123 and 1236 entries. Does a way exist to force an EXACT match when using the if __ and __ then operation.</p>
  
  <p>Or does anyone have an improve suggestion how to achieve this ...</p>
  
  <p>Thanks in advance for any pointers. Cheers</p>