how to delete lowercase words from a string in python
I'm new in python and I'm having some issues doing a simple thing.
I've an array (or list as it's said in python) like this:
list = [ 'NICE dog' , 'blue FLOWER' , 'GOOD cat' , 'YELLOW caw']
As you see each element of this array contains some words. These words is both lowercase and uppercase.
How I can delete from this array each lowercase words?
For example I'd like to have as result this list:
list = [ 'NICE' , 'FLOWER' , 'GOOD' , 'YELLOW']
l = [ 'NICE dog' , 'blue FLOWER' , 'GOOD cat' , 'YELLOW caw'] output = [' '.join(w for w in a.split() if w.isupper()) for a in l] # or: output = [' '.join(filter(str.isupper, a.split())) for a in l]
['NICE', 'FLOWER', 'GOOD', 'YELLOW']
(Don't use list as variable name.)