title: combining data between two time stamps from two files
body: <p>I have two files to be compared and the words in one file is split into multiple segments of another file. I need to find a way to map the segments with the original word/phrase.</p>
  
  <p>In the given files I use the timestart and time end of a word in Chinese and compared the phoneset that come under this time stamp and printed those values for the Chinese word.</p>
  
  <p>The files I used are:<br>
  reference file: <a href="https://ufile.io/7lze7" rel="nofollow noreferrer">https://ufile.io/7lze7</a><br>
  segments file: <a href="https://ufile.io/rysz4" rel="nofollow noreferrer">https://ufile.io/rysz4</a></p>
  
  <p>The code I have tried so far:</p>
  
  <pre><code>    outfile=open("lexlog",'w')
  
      phoneme=[]
      with open("ref.txt"+file,'r') as sylfile:
          for lines in sylfile:
              start,end,syl=lines.split()
              #print "from syl "+start,end
              with open("hyp.txt", 'r') as phnfile:
                  for line in phnfile:
                      startphn, endphn, sylphn = line.split()
                      if (startphn&gt;=start) and (endphn&lt;=end) and (startphn&lt;endphn):
                          phoneme.append(sylphn)
                          print `enter code here`sylphn
                          outfile.write(startphn+" "+start+" "+endphn+" "+end)
                  print file,syl,' '.join(phoneme)
                  outfile.write(file+" "+syl+" "+' '.join(phoneme)+"\n")
                  phoneme=[]
  </code></pre>
  
  <p>The result I expect is in the form of:</p>
  
  <pre class="lang-none prettyprint-override"><code>ref.txt !SIL SIL
  ref.txt 非 F EI
  ref.txt 生 SH AH NG
  ref.txt 物 U
  ref.txt 物 U
  ref.txt 體 T I
  ref.txt 也 I E
  ref.txt 會 H U EI
  ref.txt 有 I OU 
  ref.txt 一 I
  ref.txt 種 ZH O NG
  ref.txt 被 B EI
  ref.txt 稱 CH AH NG
  ref.txt 作 Z U O
  ref.txt 自 Z IH
  ref.txt 殺 SH A
  ref.txt 的 D AH
  ref.txt 設 SH AH
  ref.txt 計 J I
  ref.txt !SIL SIL
  ref.txt 例 L I
  ref.txt 如 R U
  ref.txt !SIL SIL
  ref.txt 人 R AH N
  ref.txt 工 G O NG
  ref.txt 智 ZH IH
  ref.txt 慧 H U EI
  ref.txt !SIL SIL
  ref.txt 在 Z AI
  ref.txt 被 B EI
  ref.txt 電 D I E N
  ref.txt 腦 N AU
  ref.txt 病 B I NG
  ref.txt 毒 D U
  ref.txt 入 R U
  ref.txt 侵 Q I N
  ref.txt 的 D AH
  ref.txt 情 Q I NG
  ref.txt 況 K U A NG
  ref.txt 下 X I A
  ref.txt !SIL SIL
  ref.txt 會 H U EI
  ref.txt 啟 Q I
  ref.txt 動 D O NG
  ref.txt 殺 SH A
  ref.txt 毒 D U
  ref.txt 程 CH AH NG
  ref.txt 系 X I
  ref.txt !SIL SIL
  ref.txt 同 T O NG
  ref.txt 時 SH IH
  ref.txt 刪 SH A N
  ref.txt 除 CH U
  ref.txt 自 Z IH
  ref.txt 己 J I
  ref.txt 體 T I
  ref.txt 內 N EI
  ref.txt 的 D AH
  ref.txt 檔 D A NG
  ref.txt 案 A N
  ref.txt !SIL SIL
  </code></pre>
  
  <p>but the output is:</p>
  
  <pre class="lang-none prettyprint-override"><code>ref.txt !SIL SIL 
  ref.txt 非 F EI 
  ref.txt 生 SH AH NG 
  ref.txt 物 U 
  ref.txt 物 U 
  ref.txt 體 T I 
  ref.txt 也 I E 
  ref.txt 會 H U EI 
  ref.txt 有 I OU A D U CH AH NG X I SIL T O NG SH IH SH A N CH U Z IH J I T I N EI D AH D A NG A N SIL 
  ref.txt 一 I 
  ref.txt 種 ZH O NG 
  ref.txt 被 B EI 
  ref.txt 稱 CH AH NG 
  ref.txt 作 Z U O 
  ref.txt 自 Z IH 
  ref.txt 殺 SH A 
  ref.txt 的 D AH 
  ref.txt 設 SH AH 
  ref.txt 計 J I 
  ref.txt !SIL SIL 
  ref.txt 例 L I 
  ref.txt 如 R U 
  ref.txt !SIL SIL 
  ref.txt 人 R AH N 
  ref.txt 工 G O NG 
  ref.txt 智 ZH IH 
  ref.txt 慧 H U EI 
  ref.txt !SIL SIL 
  ref.txt 在 Z AI 
  ref.txt 被 B EI 
  ref.txt 電 D I E N 
  ref.txt 腦 N AU 
  ref.txt 病 B I NG 
  ref.txt 毒 D U 
  ref.txt 入 R U 
  ref.txt 侵 Q I N 
  ref.txt 的 D AH 
  ref.txt 情 Q I NG 
  ref.txt 況 K U A NG 
  ref.txt 下 X I A 
  ref.txt !SIL SIL 
  ref.txt 會 H U EI 
  ref.txt 啟 Q I 
  ref.txt 動 D O NG 
  ref.txt 殺  
  ref.txt 毒 D U 
  ref.txt 程 CH AH NG 
  ref.txt 系 X I 
  ref.txt !SIL SIL 
  ref.txt 同 T O NG 
  ref.txt 時 SH IH 
  ref.txt 刪 SH A N 
  ref.txt 除 CH U 
  ref.txt 自 Z IH 
  ref.txt 己 J I 
  ref.txt 體 T I 
  ref.txt 內 N EI 
  ref.txt 的 D AH 
  ref.txt 檔 D A NG 
  ref.txt 案 A N 
  ref.txt !SIL SIL
  </code></pre>
  
  <p>Somehow the eighth line in the output gets a different result to what I expected. Any help is appreciated.</p>