a -very- case sensitive search

John Machin sjmachin at lexicon.net
Sat Nov 25 18:22:06 EST 2006


Dustan wrote:
> Steven D'Aprano wrote:
> > On Sat, 25 Nov 2006 13:39:55 -0800, Ola K wrote:
> >
> > > Hi,
> > > I am pretty new to Python and I want to make a script that will search
> > > for the following options:
> > > 1) words made of uppercase characters -only- (like "YES")
> > > 2) words made of lowercase character -only- (like "yes")
> > > 3) and words with only the first letter capitalized (like "Yes")
> > > * and I need to do all these considering the fact that not all letters
> > > are indeed English letters.
> > >
> > > I went through different documention section but couldn't find a right
> > > condition, function or method for it.
> >
> > At the command prompt:
> >
> >
> > >>> dir('')
> > # result edited for clarity
> > [ ... 'isalnum', 'isalpha', 'isdigit', 'islower',
> > 'isspace', 'istitle', 'isupper',  ... ]
> >
> > Then do this:
> >
> > >>> help(''.islower)
> >
> > and read the text it provides. Then experiment on the command line:
> >
> > >>> 'abcd1234'.islower()
> > True
> > >>> 'aBcd1234'.islower()
> > False
>
> Forget what I said; I didn't know about the str.is* methods.

... or about the unicode.is* [same bunch of] methods, which may
possibly address the OP's
"not all letters are indeed English letters" concerns. If he's stuck
with 8-bit str objects, he may need to ensure the locale is set
properly, as vaguely hinted at in the docs that Steven pointed him to.

Cheers,
John




More information about the Python-list mailing list