Python idiom: Multiple search-and-replace

Randall Hopper aa8vb at yahoo.com
Wed Apr 12 18:07:51 CEST 2000


Darrell Gallion:
 |My solution is more work than Fredrik's, unless you
 |plan on making a lot of changes to the buffer.
 |Like many hundreds of patterns on a large buffer.
 |
 |Keep a list of changes to be performed.
 |(start, seqNumber, text, end)
 |
 |seqNumber stabilizes the sort of this list.
 |
 |If the start==end then delete a section.
 |
 |Sort the list and perform all operations at once.
 |This is like a transaction, which allows for some
 |other cool features. Such as detecting conflicting or
 |overlapping changes. 
 |
 |I have code if you want it.

For the dataset and change sizes I'm working with, Fredrick's re
replacement function approach gets the running time down sufficiently.
Thanks for the reply though.  I'll keep your technique in mind if I'm faced
with much larger datasets.

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list