Another possibility is to form a suffix array
(https://en.wikipedia.org/wiki/Suffix_array#Applications) as an index for the
string, and then search for patterns within the suffix array. The basic idea
is that you index the string you're searching over once, and then look for
patterns within it
If you can use third party library, I think you can use Aho-Corasick algorithm.
https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm
https://pypi.python.org/pypi/pyahocorasick/
On Sat, Feb 25, 2017 at 3:54 AM, wrote:
> I have a task to search for multiple patterns in incoming string an
On Friday, February 24, 2017 at 2:41:58 PM UTC-8, Erik wrote:
> On 24/02/17 22:18, kar wrote:
> > Thanks, what is the idea behind storing the keys and values in a list, I
> > assume looking up for a value in a map is faster getting the value from the
> > list.
>
> What do you not understand? MRA
On 24/02/17 22:18, kar wrote:
Thanks, what is the idea behind storing the keys and values in a list, I assume
looking up for a value in a map is faster getting the value from the list.
What do you not understand? MRAB's extensive comments explain what is
being done and why.
In summary, the
On 2017-02-24 22:18, kar wrote:
On Friday, February 24, 2017 at 11:48:22 AM UTC-8, MRAB wrote:
On 2017-02-24 18:54, kar6...@gmail.com wrote:
> I have a task to search for multiple patterns in incoming string and replace
with matched patterns, I'm storing all pattern as keys in dict and replacem
On Friday, February 24, 2017 at 11:48:22 AM UTC-8, MRAB wrote:
> On 2017-02-24 18:54, kar6...@gmail.com wrote:
> > I have a task to search for multiple patterns in incoming string and
> > replace with matched patterns, I'm storing all pattern as keys in dict and
> > replacements as values, I'm us
On 24/02/17 18:54, kar6...@gmail.com wrote:
for example is the search string is not a variable we can say
re.search(r"\$%^search_text", "replace_text", "some_text") but when I
read from the dict where shd I place the "r" keyword, unfortunately
putting inside key doesnt work "r key" like this
On 2017-02-24 18:54, kar6...@gmail.com wrote:
I have a task to search for multiple patterns in incoming string and replace
with matched patterns, I'm storing all pattern as keys in dict and replacements
as values, I'm using regex for compiling all the pattern and using the sub
method on patter
I have a task to search for multiple patterns in incoming string and replace
with matched patterns, I'm storing all pattern as keys in dict and replacements
as values, I'm using regex for compiling all the pattern and using the sub
method on pattern object for replacement. But the problem I have