Not x.islower() has different output than x.isupper() in list output...
Christopher Reimer
christopher_reimer at icloud.com
Fri Apr 29 21:17:34 EDT 2016
Greetings,
I was playing around with a piece of code to remove lowercase letters
and leave behind uppercase letters from a string when I got unexpected
results.
string = 'Whiskey Tango Foxtrot'
list(filter((lambda x: not x.islower()), string))
['W', ' ', 'T', ' ', 'F']
Note the space characters in the list.
list(filter((lambda x: x.isupper()), string))
['W', 'T', 'F']
Note that there are no space characters in the list.
Shouldn't the results between 'not x.islower()' and 'x.isupper()' be
identical?
The final form of this code is this:
list(filter(str.isupper, string))
['W', 'T', 'F']
Thank you,
Chris R.
More information about the Python-list
mailing list