High memory usage - program mistake or Python feature?

Jack Diederich jack at performancedrivers.com
Fri May 23 09:01:32 EDT 2003


>   # { 'command' : compiled_re }
>   cmd_res = dict(zip(cmds, map(re.compile, cmds)))

Woops, I forgot the important part of the regular expression, that should be

cmd_res = dict(zip(cmds, [re.compile(' Log \w+: %s " % (x)) for x in cmds]))

or if you don't prefer lambdas (I do, largely from pre-python baggage)

cmd_res = dict(zip(cmds, map(lambda x:re.compile(' Log \w+: %s " % (x)), cmds)))

but now that line is getting long and busy, better to do

cmd_raw_res = [re.compile(' Log \w+: %s " % (x)) for x in cmds]
cmd_res = dict(zip(cmds, cmd_raw_res))

-jackdied





More information about the Python-list mailing list