Most efficient way for a lookup/search in a huge list (python)
Posted
by user229269
on Stack Overflow
See other posts from Stack Overflow
or by user229269
Published on 2010-04-23T18:47:52Z
Indexed on
2010/04/23
18:53 UTC
Read the original article
Hit count: 256
Hey guys, -- I just parsed a big file and I created a list containing 42.000 strings/words. I want to query [against this list] to check if a given word/string belongs to it. So my question is: What is the most efficient way for such a lookup? A first approach is to sort the list [list.sort()] and then just use the >> if word in list: print 'word' -- which is really trivial and I am sure there is a better way to do it. My goal is to apply a fast lookup that finds whether a given string is in this list or not. If you have any ideas of another data structure, they are welcome. Yet, I want to avoid for now more sophisticated data-structures like Tries etc. I am interested in hearing ideas (or tricks) about fast lookups or any other python library methods that might do the search faster than the simple 'in'. Thanks in advance!
© Stack Overflow or respective owner