How to extract all UPPER from a string? Python

后端 未结 7 2130
终归单人心
终归单人心 2020-12-31 04:51
#input
my_string = \'abcdefgABCDEFGHIJKLMNOP\'

how would one extract all the UPPER from a string?

#output
my_upper = \'ABCDEFGHIJKL         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 05:36

    You could use a more functional approach

    >>> s = 'abcdefgABCDEFGHIJKLMNOP'
    >>> filter(str.isupper, s)
    'ABCDEFGHIJKLMNOP'
    

提交回复
热议问题