Hej,
Mam zadanie w którym chce określić czy dany ciąg znaków składa się tylko z samych dużych liter.
Jeśli tak to ma zwrócić True. W przeciwnym razie False.
Oto co do tej pory mi się udało zrobić:
import re
def is_all_upper(text):
# your code here
str_len = len(text)
m = re.search(f'[A-Z]{str_len}', text)
return m
print(is_all_upper('ALL UPPER')) # == True
print(is_all_upper('all lower')) # == False
print(is_all_upper('mixed UPPER and lower')) # == False
print(is_all_upper('')) # == True
Problem mam z wstawieniem str_len do tego wyrażenia regularnego. Czy może ktoś wytłumaczyć jak to zrobić.
Konsola mi zwraca same None jak na razie.
Pozdrawiam.
----------
EDITED:
Poradziłem już sobie z zadaniem. Oto mój kod:
def is_all_upper(text: str) -> bool:
if len(text) <= 0:
return True
if text[0] == " ":
return True
digit_list = ["1", "2" , "3", "4", "5", "6", "7", "8", "9", "0"]
for digit in digit_list:
if digit in text:
return True
return text.isupper()