⚡ 60 segundos
funcoes
Verificar condições com any() e all()
any() retorna True se pelo menos um for verdadeiro. all() exige que todos sejam. Código limpo sem for.
any_all.py
notas = [7.5, 8.0, 4.5, 9.0]
# Alguem reprovou? (nota < 5)
print(any(n < 5 for n in notas)) # True
# Todos aprovados? (nota >= 5)
print(all(n >= 5 for n in notas)) # False
# Util com listas vazias
print(all([])) # True
print(any([])) # False