shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Tue Jun 24 20:47:58 CEST 2008


On 24 juin, 20:32, cirfu <circularf... at yahoo.se> wrote:
> if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":
>
> cant i write something like:
> if char in "[A-Za-z]":
>

Nope. But there are other solutions. Here are two:

# 1
import string

if char in string.letters:
   print "yay"

# 2
import re
exp = re.compile(r'[A-Za-z]')

if exp.match(char):
   print "yay"




More information about the Python-list mailing list