[Tutor] Function problem

R. Alan Monroe amonroe at columbus.rr.com
Sat Nov 6 20:27:02 CET 2004


> 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

Alan



More information about the Tutor mailing list