[Tutor] Function problem

Bob Gailer bgailer at alum.rpi.edu
Sat Nov 6 21:26:09 CET 2004


At 12:27 PM 11/6/2004, R. Alan Monroe wrote:
> > At 12:26 PM 11/6/2004 +0300, Eri Mendz wrote:
> >>I also want to use regular expression for the Y|N portion; e.g.,
> >>something like if ask == [Y|y|ye|yes] or ask == [N|n|no|nope]... to that
> >>effect. Any help is appreciated.
>
> > import re
> > yes = re.compile('y|ye|yes', re.IGNORECASE)
> > if yes.match(ask):
> >          ...
>
> > This will also match 'you' and 'yesterday', if you want to be stricter
> > change the RE to '(y|ye|yes)$'
>
>This might be quicker and cleaner than re:
>
>if ask.upper().startswith('Y'):
>    #do stuff

I still favor:

if 'YES'.startswith(ask.upper())

Covers all cases and abbreviations.

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 



More information about the Tutor mailing list