Re: prefix search on a large file

2006-10-13 Thread js
I did the test the way you suggested. It took not so long to realize stupid mistakes I made. Thank you. The following is the result of test with timeit(number=1) using fresh copy of the list for every iteration 0.331462860107 0.19401717186 0.186257839203 0.0762069225311 I tried my recursive

Re: prefix search on a large file

2006-10-12 Thread Scott David Daniels
Tim Chase wrote: >> def leaders(sorted_list): >> held = None >> for phrase in held: > ... I suspect you mean > for phrase in sorted_list: > no? Ooops -- renaming code before posting should get its own test. You are absolutely correct. --Scott David Daniels [EMAIL PROTE

Re: prefix search on a large file

2006-10-12 Thread Tim Chase
> def leaders(sorted_list): > held = None > for phrase in held: Ummm...that for phrase in None: doesn't do a whole lot other than give a traceback. :*) I suspect you mean for phrase in sorted_list: no? -tkc -- http://mail.python.org/mailman/listinfo/

Re: prefix search on a large file

2006-10-12 Thread Scott David Daniels
Try: def leaders(sorted_list): held = None for phrase in held: if held is None or not phrase.startswith(held): held = row yield held print list(leaders(sorted(data))) --Scott David Daniels [EMAIL PROTECTED] -- http://ma

Re: prefix search on a large file

2006-10-12 Thread Peter Otten
js wrote: > By eliminating list cloning, my function got much faster than before. > I really appreciate you, John. > > def prefixdel_recursively2(alist): > if len(alist) < 2: > return alist > > first = alist.pop(0) > unneeded = [no for no, line in enumerate(alist) if > line.star

Re: prefix search on a large file

2006-10-12 Thread js
By eliminating list cloning, my function got much faster than before. I really appreciate you, John. def prefixdel_recursively2(alist): if len(alist) < 2: return alist first = alist.pop(0) unneeded = [no for no, line in enumerate(alist) if line.startswith(first)] adjust=0

Re: prefix search on a large file

2006-10-12 Thread js
Thank you for the quick reply. Here're the exact code I executed. (including your code) #!/usr/bin/env python from pprint import pprint as pp data = [ 'foo bar baz', 'foo bar', 'foo', 'food', 'food', # duplicate 'xyzzy', 'plugh', 'xyzzy and plugh are magic', '',

Re: prefix search on a large file

2006-10-12 Thread John Machin
js wrote: > Hello, list. > > I have a list of sentence in text files that I use to filter-out some data. > I managed the list so badly that now it's become literally a mess. > > Let's say the list has a sentence below > > 1. "Python has been an important part of Google since the beginning, > and

prefix search on a large file

2006-10-12 Thread js
Hello, list. I have a list of sentence in text files that I use to filter-out some data. I managed the list so badly that now it's become literally a mess. Let's say the list has a sentence below 1. "Python has been an important part of Google since the beginning, and remains so as the system