464,776 Members | 1,190 Online
Need help? Post your question and get tips & solutions from a community of 464,776 IT Pros & Developers. It's quick & easy.

# shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":

 P: n/a if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz": cant i write something like: if char in "[A-Za-z]": ? Jun 27 '08 #1
9 Replies

 P: n/a cirfu wrote: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz": cant i write something like: if char in "[A-Za-z]": Either of the following should do what you want, without resorting to regular expressions: import string if char in string.letters: or if char.isalpha(): -- Brian Jun 27 '08 #2

 P: n/a On 24 juin, 20:32, cirfu

 P: n/a On Tue, Jun 24, 2008 at 3:47 PM, br*****************@gmail.com if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":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" Let me post another one, and longer: if ord(somechar) in range(ord('A'), ord('Z') + 1) + range(ord('a'), ord('z') + 1): ... -- -- Guilherme H. Polo Goncalves Jun 27 '08 #4

 P: n/a another way: import string if char in string.ascii_letters: print('hello buddy!') []'s - Walter Jun 27 '08 #5

 P: n/a On Jun 24, 7:59*pm, "Guilherme Polo"

 P: n/a On Jun 25, 4:32 am, cirfu

 P: n/a On Jun 24, 5:36 pm, John Machin

 P: n/a On Jun 25, 9:06 am, s0s...@gmail.com wrote: On Jun 24, 5:36 pm, John Machin

 P: n/a Guilherme Polo

### This discussion thread is closed

Replies have been disabled for this discussion.