title: Wrong list being returned in python
body: <pre><code>def mainCall(nodeGroup):
  
      maxScore = -9999999
      maxPart = []
      tempPartition = []
      tempScore = 0.0
  
      for j in range(2, 1+nodes/2):
  
          nodeGroup = chooseInitPartition(j, nodeGroup)
          tempScore, tempPartition = runKL(edgeList, nodeGroup, rounds)
          print 'temp score', tempScore
          print 'temp part', tempPartition, "\n"
          if(maxScore &lt; tempScore):
              maxScore = tempScore
              maxPart = tempPartition
              print "max score", maxScore
              print "maxpart", maxPart, "\n"
  
       print 'before ret max part', maxPart
       return maxScore, maxPart
  
  finalScore, finalPartition = mainCall(nodeGroup)
  </code></pre>
  
  <p>I am having a problem with the above code. Everything seems fine till the <code>for</code> loop ends, but after that instead of printing the <code>maxPart</code> value at the line <code>print 'before ret max part'</code>, it prints the last value of <code>tempPartition</code> (both represent a list of numbers). 
  The print statements confirm that the <code>if</code> condition is not satisfied every time, especially the last few runs in the loop. So I don't see how the value of <code>tempPartition</code> is being transferred to <code>maxPart</code>. Please help me with this. It is driving me crazy. I am sure I am missing something simple. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Adding code for <code>runKL</code></p>
  
  <pre><code>def runKL(edgeList, nodeGroup, rounds):
  
      nodeSwap = [0]*nodes
      maxLogLScore = 0.0
      edgeListLen = len(edgeList)
  
      networkPartitionStore = []
      logLScores = []
  
      #Reset count
      count = 0
  
      #Start main loop
      for i in range(rounds):
          #mark all vertices as unswapped
          for j in range(len(nodeSwap)):
              nodeSwap[j] = 0
  
  
          while(count &lt; 100):
              #Choose one edge uniformly randomly
              randNum = random.uniform(0,1)
              edge = edgeList[int(math.floor(edgeListLen*randNum))]
              node1 = int(edge[0]) - 1
              node2 = int(edge[1]) - 1
  
              if((nodeGroup[node1] == nodeGroup[node2]) or (nodeSwap[node1] == 1) or (nodeSwap[node2] == 1)):
                  count += 1
                  continue
              else:
                  #swap groups among nodes
                  temp = nodeGroup[node1]
                  nodeGroup[node1] = nodeGroup[node2]
                  nodeGroup[node2] = temp
  
                  #mark vertices as swapped
                  nodeSwap[node1] = 1
                  nodeSwap[node2] = 1
  
                  #calculate likelihood
                  logLScore = logLikelihood(edgeList, nodeGroup)
                  logLScores.append(logLScore)
  
                  #store network
                  networkPartitionStore.append(nodeGroup)
  
                  #reset count value
                  count = 0
  
          #end while loop
  
          #Choose the index of the maximum likelihood score
          maxLogLScore = max(logLScores)
          index = logLScores.index(maxLogLScore)
          #print 'max score', modularityScores[index]
  
          #Choose the corresponding network partition i.e. the way the groups have been assigned to the nodes
          nodeGroup = networkPartitionStore[index]
  
          #Reset partition storage list and modularity scores
          networkPartitionStore = []
          logLScores = []
  
          #Store initial network partition structure and modularity score. 
          networkPartitionStore.append(nodeGroup)
          logLScores.append(maxLogLScore)
  
      return maxLogLScore, nodeGroup
  </code></pre>