0

Curious to see if there's a way to return all capital letters from a string in Python, not using is.upper, maybe using other conditionals?

svlk
  • 511
  • 1
  • 4
  • 7

2 Answers2

3

One solution would be:

[char for char in _string if char.isupper()]
Thomas Junk
  • 5,588
  • 2
  • 30
  • 43
1

Without using anything other than list comprehension (that too can be replaced by normal for loop)

>>> [s for s in string if 'A'<=s<='Z']
=> ['A', 'D', 'F', 'G']

#driver values :

IN : string = 'AbcDeFGh2i'
Kaushik NP
  • 6,733
  • 9
  • 31
  • 60