Iterating across a filtered list

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Mar 13 17:31:10 EDT 2007


En Tue, 13 Mar 2007 17:19:53 -0300, Arnaud Delobelle  
<arnodel at googlemail.com> escribió:

> On Mar 13, 7:36 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>>
>> The re library caches the compiled regexp, I think.
>
> That would surprise me.
> How can re.search know that string.lower(search) is the same each
> time?  Or else there is something that I misunderstand.

It does.

py> import re
py> x = re.compile("ijk")
py> y = re.compile("ijk")
py> x is y
True

Both, separate calls, returned identical results. You can show the cache:

py> re._cache
{(<type 'str'>, '%(?:\\((?P<key>.*?)\\))?(?P<modifiers>[-#0-9  
+*.hlL]*?)[eEfFgGd
iouxXcrs%]', 0): <_sre.SRE_Pattern object at 0x00A786A0>,
  (<type 'str'>, 'ijk', 0): <_sre.SRE_Pattern object at 0x00ABB338>}

-- 
Gabriel Genellina




More information about the Python-list mailing list