title: Python process data statistics runs very slow while using tuple in dictionary
body: <p>I wrote a python script to calculate the min, max, avg values of items in a file.
  However the program runs slower and slower after few hundred k lines. I can make perl do the same thing very fast but I want to learn the right way in Python. Is there anyway to  speed up it?</p>
  
  <pre><code>import sys
  import re
  
  
  filename = sys.argv[1]
  resultFile = open(filename, 'r')
  
  netTbl = {}
  count = 0;
  # Target file line example: "itemA: 0.110"
  matchLine = re.compile( r"(.*):\s+([0-9\.]+)" )
  for line in resultFile:
      result = matchLine.match(line);
      if( result ) :
          count +=1 
          if( count%10000 == 0 ): print str(count) + ":" + str(len(netTbl))
  
          name =  result.group(1)
          value = result.group(2)
  
          if( netTbl.has_key(name) ):
              ( minVal, maxVal, avgVal, numOfInsts ) = netTbl[name]
  
              if( maxVal &lt; value ): maxVal = value
              if( minVal &gt; value ): minVal = value
  
              avgVal += value
              numOfInsts += 1
              netTbl[name] = ( minVal, maxVal, avgVal, numOfInsts)
          else:
              netTbl[name] = (value, value, value, 1)
  </code></pre>
  
  <p>The input file is like</p>
  
  <pre><code>itemA: 0.1
  itemA: 2.1
  itemA: 0.4
  itemA: 0.2
  .....
  ..... (repeat itemA for million lines)
  itemB: 2.9
  itemB: 3.8
  itemB: 5.76
  itemB: 6.3
  ..... (repeat itemB for million lines)
  </code></pre>
  
  <p>I have got the answer. I forget to cast value to float. So the string is getting larger and larger. To correct the code</p>
  
  <pre><code>#value = result.group(2)
  value = float(result.group(2))
  </code></pre>