Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107887

Re: Not x.islower() has different output than x.isupper() in list output...

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Not x.islower() has different output than x.isupper() in list output...
Date 2016-04-30 12:10 +1000
Message-ID <mailman.244.1461982253.32212.python-list@python.org> (permalink)
References <572407AE.1070703@icloud.com> <1461979797.3824480.593944273.0B8D8DF3@webmail.messagingengine.com> <57241097.7020801@icloud.com> <CAPTjJmrgtnpPSfdCqa6fyNT0FwY3jckqwr8Vqq4MZ8JCZ5V5cg@mail.gmail.com>

Show all headers | View raw


On Sat, Apr 30, 2016 at 11:55 AM, Christopher Reimer
<christopher_reimer@icloud.com> wrote:
> On 4/29/2016 6:29 PM, Stephen Hansen wrote:
>>
>> If isupper/islower were perfect opposites of each-other, there'd be no
>> need for both. But since characters can be upper, lower, or *neither*, you
>> run into this situation.
>
>
> Based upon the official documentation, I was expecting perfect opposites.
>
> str.islower(): "Return true if all cased characters [4] in the string are
> lowercase and there is at least one cased character, false otherwise."
>
> https://docs.python.org/3/library/stdtypes.html?highlight=islower#str.islower
>
> str.isupper(): "Return true if all cased characters [4] in the string are
> uppercase and there is at least one cased character, false otherwise."
>
> https://docs.python.org/3/library/stdtypes.html?highlight=isupper#str.isupper
>
> Here's the footnote that may or not be relevant to this discussion: "[4]
> Cased characters are those with general category property being one of “Lu”
> (Letter, uppercase), “Ll” (Letter, lowercase), or “Lt” (Letter, titlecase)."
>
> A bug in the docs?

>>> def case(ch):
...     return (
...         ("Lower " if ch.islower() else "") +
...         ("Upper " if ch.isupper() else "") +
...         unicodedata.category(ch)
...     )

Both functions require that there be at least one cased character:

>>> case("@")
'Po'

And then each one requires a specific character class:

>>> case("a")
'Lower Ll'
>>> case("A")
'Upper Lu'

Other classes don't count:

>>> case("\u01C5")
'Lt'

There are three categories of "cased characters". Both functions check
for exactly one of those categories. Thus they are not opposites.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Not x.islower() has different output than x.isupper() in list output... Chris Angelico <rosuav@gmail.com> - 2016-04-30 12:10 +1000

csiph-web