Python replace multiple strings (m*n) combination

Erik python at lucidity.plus.com
Fri Feb 24 17:41:39 EST 2017


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 keys and values are put into lists so that the keys can 
be given an explicit order for the re.compile() and then the subsequent 
lookup when a match is found is via a numeric index (which is even 
faster for a list than a key lookup is for a dict (map)).

E.



More information about the Python-list mailing list