From: Paul Nulty Date: 2007-03-12T02:25:08+09:00 Subject: Re: Opening a large file many times / optimisation > > 1. You need to define the problem better. Are you searching for a > different word each time, does the file change each time, etc. Why do > you have to call it 1400 times? ok here's a few lines from the file i'm searching (its a wordnet file that holds different senses of words) concavity%1:07:00:: 05070032 2 0 concavity%1:25:00:: 13864965 1 0 concavo-concave%5:00:00:concave:00 00536008 1 0 concavo-convex%5:00:00:concave:00 00536416 1 0 conceal%2:39:00:: 02146790 2 1 conceal%2:39:01:: 02144835 1 8 concealed%3:00:00:: 02088404 2 1 concealed%5:00:00:invisible:00 02517817 1 2 concealing%1:04:00:: 01048912 1 0 concealing%3:00:00:: 02091020 1 0 i need to search for the first part (e.g. conceal%2:39:00::) and return the second last number (eg. 2). (getting the sense from the sense key, if you know wordnet) i have 1400 words, the wordnet file will never change. i'm unlikely to need to scale up much past 1400. here's my code: (senseKey is eg "conceal%2:39:00::") lines=File.readlines("/usr/local/WordNet-3.0/dict/index.sense") #gets a sysnet number from a sense key def getSense(senseKey,lines) for line in lines if line.index(senseKey)==0 words=line.split(" ") return words[-2] end end end thanks again!