shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":
sjmachin at lexicon.net
Wed Jun 25 02:36:10 CEST 2008
On Jun 25, 9:06 am, s0s... at gmail.com wrote:
> On Jun 24, 5:36 pm, John Machin <sjmac... at lexicon.net> wrote:
> > On Jun 25, 4:32 am, cirfu <circularf... at yahoo.se> wrote:
> > > if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":
> > > cant i write something like:
> > > if char in "[A-Za-z]":
> > You can write that if you want to, but it's equivalent to
> > if char in "zaZa]-[":
> > i.e. it doesn't do what you want.
> > This gives the same reuslt as your original code, unaffected by
> > locale:
> > if "A" <= char <= "Z" or "a" <= char <= "z":
> But doesn't that rely on the underlying character set?
Unless there is a Python implementation using EBCDIC, different
underlying character set that differs from ASCII in A..Z and a..z is
*not* a practical concern.
> It's like
> performing math on C char's (maybe that's what the interpreter does
> internally?). If that's the case, using 'char.isalpha()' or 'char in
> string.letters' or regex's would be better.
You should be asking the OP what he really wants ... precisely those
letters? alphabetic, in what locale?
More information about the Python-list