Optimizing multiple searches
- Posted by rneu Jun 28, 2017
- 1347 views
CODE:
sequence lines = {"this is first line", "second line", "another line", "and this is another line- will be fourth", "and last line"} sequence terms = {"line", "will", "this"} sequence outlist = {} for i=1 to length(terms) do for j=1 to length(lines) do if match(terms[i], lines[j]) then outlist = append(outlist, lines[j]) end if end for lines = outlist outlist = {} end for display(lines)
Output:
{ "and this is another line- will be fourth" }
I have 2 lists (lines and terms) and I have to select out only those entries of 'lines' where all items of 'terms' are present. Above code works but can it be optimized or shortened since I see that functions such as match_all, find_all, find_each etc are also available?
(Not able to put hashes for code in above text).