This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ProFatXuanAll
Recipients ProFatXuanAll, ezio.melotti, mrabarnett
Date 2020-11-26.18:29:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606415375.3.0.603801258306.issue42475@roundup.psfhosted.org>
In-reply-to
Content
When I run the following code, I expected to get output result `['i am next line with [unk]']`, but instead I get the original list in `data`.

Code snippet

```py
import re

data = [
    '= hello =',
    'i am next line with <unk>',
]

pttn = re.compile(r'=.*=')
samples = filter(lambda sample: not pttn.match(sample), data)

pttn = re.compile(r'<unk>')
samples = map(lambda sample: pttn.sub('[unk]', sample), samples)

print(list(samples))
```

I suspect that is the cache provide by `re.compile` cause the problem.
The `sub` function in `map` is somehow begin link to the first `pttn`.

If I instead rename the second `pttn` to `pttn2`, then it work magically, but this is not expected.
History
Date User Action Args
2020-11-26 18:29:35ProFatXuanAllsetrecipients: + ProFatXuanAll, ezio.melotti, mrabarnett
2020-11-26 18:29:35ProFatXuanAllsetmessageid: <1606415375.3.0.603801258306.issue42475@roundup.psfhosted.org>
2020-11-26 18:29:35ProFatXuanAlllinkissue42475 messages
2020-11-26 18:29:35ProFatXuanAllcreate