idiom for RE matching

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Jul 25 02:52:35 EDT 2007


Gordon Airporte <JHoover at fbi.gov> writes:

> I did already find that it speeds things up to pre-test a line like
> 
> if 'bets' or 'calls' or 'raises' in line:
> 	run the appropriate re's
> 
> which isn't very pretty at all

Nor does it work the way you might suppose:

    >>> line = "foo calls"
    >>> if 'bets' or 'calls' or 'raises' in line:
    ...     print "Yes"
    ... 
    Yes
    >>> line = "spam eggs"
    >>> if 'bets' or 'calls' or 'raises' in line:
    ...     print "Yes"
    ... 
    Yes

Hint: the expression being evaluated for the 'if' statement above is
equivalent to:

    if (('bets') or ('calls') or ('raises' in line)):
        print "Yes"

-- 
 \           "An eye for an eye would make the whole world blind."  -- |
  `\                                                    Mahatma Gandhi |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list