regex - How to compile multiple multiple regexes in one go? Is it more efficient? - python -


let's have code such:

import re docid_re = re.compile(r'<docid>([^>]+)</docid>') doctype_re = re.compile(r'<doctype source="[^"]+">([^>]+)</doctype>') datetime_re = re.compile(r'<datetime>([^>]+)</datetime>') 

i this:

>>> import re >>> docid_re = r'<docid>([^>]+)</docid>' >>> doctype_re = r'<doctype source="[^"]+">([^>]+)</doctype>' >>> datetime_re = r'<datetime>([^>]+)</datetime>' >>> docid_re, doctype_re, datetime_re = map(re.compile, [docid_re, doctype_re, datetime_re]) >>> docid_re <_sre.sre_pattern object @ 0x7f0314eee438> 

but there real gain in speed or memory when use map()?

do not listen - measure it! can use timeit module it. remember, "premature optimization root of evil" (c) donald knuth.

btw, answer on question "no, doesn't @ all".


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

excel - I can't get the attachement of the email PHP -

node.js - Express and Redis - If session exists for this user, don't allow access -