On Sun, Nov 23, 2008 at 2:55 PM, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> On Sun, 23 Nov 2008 17:55:48 +0000, Arnaud Delobelle > <[EMAIL PROTECTED]> wrote: > >But there is no reason why you should use a dictionary; just use a list > >of key-value pairs: > > > >patterns = [ > > ("pattern1", re.compile(">.+?</td>.+?>(.+?)</td>"), > > Thanks for the tip, but... I thought that lists could only use integer > indexes, while text indexes had to use dictionaries. In which case do > we need dictionaries, then? > -- Lists do use integer indexes. Since you never use the dict[key] syntax, you don't need key value pairs like that. Instead, the example uses two-item tuples. >>> patterns = [("pattern1", re.compile(">.+?</td>.+?>(.+?)</td>")), ("pattern2", re.compile("something else"))] >>> patterns[0] ('pattern1', <_sre.SRE_Pattern object at 0x3c7a0>) >>> for pattern, regex in patterns : ... print pattern + ":" + str(regex) ... pattern1:<_sre.SRE_Pattern object at 0x3c7a0> pattern2:<_sre.SRE_Pattern object at 0x35860> > > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list