title: Comparing two database records at a time in python
body: <p>I'm trying to compare pairs of students in a database table.
  My database table is as follows:</p>
  
  <pre><code>    id | edu
      1  | 1
      2  | 1
      3  | 2
      4  | 2
  </code></pre>
  
  <p>I compare a pair of students at a time and if they have similar edu code I input them to a list with their id's as 1 if not 0.
  My code is as follows:</p>
  
  <pre><code>    #getting edu info
      data=curr.execute('select id,edu from student_details')
      result = curr.fetchall()
      mydic1=dict(result)
  
      data2=curr.execute('select id,edu from student_details ')
      result2 = curr.fetchall()
      mydic2=dict(result2)
  
      looping=curr.execute('select count(id) from student_details where id &lt;= 4')
      loop_times = curr.fetchall()
      count = int(loop_times[0][0])
  
      count = count + 1
      listOflist=[]
      x=0
      for i in range(1,count):
          row = [] 
          for x in range(0,i):
              row.append(0)
          for j in range(i+1, count):
              if mydic1[i]==mydic2[j]:
                 row.append(1)
              else:
                 row.append(0)
          listOflist.append(row)
        print edu
  </code></pre>
  
  <p>This prints the output according to the way I wanted as follows:</p>
  
  <pre><code>     [[0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 0]]
  </code></pre>
  
  <p>But I don't know whether this is the most efficient way of comparing database records in python. Any suggestions for improvements are welcome.</p>