uaveiro-leci/1ano/fp/extra3/ex11.py

12 lines
306 B
Python
Raw Normal View History

2023-01-10 10:45:45 +00:00
def onlyCaps(s):
# NOTE: ch.isupper() -> True if ch is uppercase.
if len(s) == 0:
return ""
if len(s) == 1:
return s if s.isupper() else ""
return s[0] + onlyCaps(s[1:]) if s[0].isupper() else onlyCaps(s[1:])
print(onlyCaps("John Fitzgerald Kennedy"))
print(onlyCaps(""))