Ignore the 'adjacent items' remark. The rest is correct ie. looking for all strings containing a substring x.
----- Original Message ----- From: Kent Johnson To: Dinesh B Vadhia Cc: tutor@python.org Sent: Thursday, April 10, 2008 6:32 AM Subject: Re: [Tutor] Searching through large number of string items Dinesh B Vadhia wrote: > The 10,000 string items are sorted. > > The way the autocomplete works is that when a user enters a char eg. > 'f', the 'f' is sent to the server and returns strings with the char > 'f'. If it is all strings containing 'f' (not all strings starting with 'f') then the binary search will not work. A database might work better for that. You can get all strings containing some substring x with [ item for item in list if x in item ] Of course that is back to linear search. You mentioned before that you want to also show adjacent items? I don't know how to do that with a database either. Kent
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor