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

Stephen Hansen me at ixokai.io
Sat Apr 30 13:11:49 EDT 2016


On Sat, Apr 30, 2016, at 09:48 AM, Christopher Reimer wrote:
> On 4/29/2016 11:43 PM, Stephen Hansen wrote:
> > The official documentation is accurate. 
> 
> That may be true on a technical level. But the identically worded text 
> in the documentation implies otherwise. 

That's the thing -- no it doesn't. The documentation is very specific:
if all cased characters in the string are lowercase, and there's at
least one cased character.

It only seems to because you're packing a loop and test on substrings
into an operation.

   list(filter((lambda x: not x.islower()), string))

Let's unpack that. This is basically what you're doing:

    result = []
    for ch in string:
        if not ch.islower():
            result.append(ch)

You're thinking of the whole "string", but you're operating on
single-character substrings, and when " ".islower() is run, its false.
Because the two-pronged test, a) if all cased characters are lowercase
and b) there is at least one cased character. b) is failing. Ergo,
you're getting the underscores.

-- 
Stephen Hansen
  m e @ i x o k a i  . i o



More information about the Python-list mailing list