title: Read relatively large file in python takes a lot of time
body: <p>i have a file of <strong>265 MB</strong> and <strong>7504527</strong> lines of <strong>text</strong>.<br>
  this loop is taking a lot of time running :  </p>
  
  <pre><code>B = namedtuple("B", ["id", "ch"])
  
  def get_tuple_from_b_string(b_str):
      return B(int(b_str.split("_")[0]),int(b_str.split("_")[1]))
  
  with open("/tmp/file.out") as test_out:
       for line in test_out:
           if line == '' or not line.startswith("["):
                continue
           bracket_index = line.find(']')
           b_str = line[1:bracket_index]
           content = line[bracket_index+1:]
           b_tuple = get_tuple_from_b_string(b_str)
           if not b_tuple in b_tupled_list:
               continue
           if not b_tuple in b_outputs:
               b_outputs[b_tuple] = ''
               b_outputs[b_tuple] += content+'\n'
  </code></pre>
  
  <p>i'm running now and still after 19:38 minutes haven't finished yet.<br>
  i tried to check strace of the process and it repeating of the lines :  </p>
  
  <blockquote>
    <p>mmap2(NULL, 3145728, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
    -1, 0xff9093fc) = 0xfffffffff4997000<br>
    munmap(0xf678b000, 3145728)</p>
  </blockquote>
  
  <p>but different addresses (which i assume it's not stuck , and still reading).<br>
  <strong>My questions are</strong> :  </p>
  
  <ul>
  <li>why is it taking long time (under the assumption that its not stuck) ?</li>
  <li>if it is stuck , how can i find out where ?  </li>
  </ul>
  
  <p>example of file content :  </p>
  
  <pre><code>[1_03]{
  [1_03]    "0": {
  [1_03]        "interfaces": {
  [1_03]            "address": [],
  [1_03]            "distribution": [],
  [1_03]            "interface": [],
  [1_03]            "netmask": []
  [1_03]        },
  </code></pre>