Aula1 finished

Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
Tiago Garcia 2024-09-28 15:25:05 +01:00
parent 44977b48d6
commit 395faca3fd
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 31 additions and 7 deletions

View File

@ -63,34 +63,58 @@ def lista_subconjuntos(lista):
# Exercicio 2.1
def separar(lista):
pass
if not lista:
return ([], [])
new_lista = separar(lista[1:])
return ([lista[0][0]] + new_lista[0], [lista[0][1]] + new_lista[1])
# Exercicio 2.2
def remove_e_conta(lista, elem):
pass
if not lista:
return ([], 0)
if lista[0] == elem:
new_lista = remove_e_conta(lista[1:], elem)
return (new_lista[0], new_lista[1] + 1)
new_lista = remove_e_conta(lista[1:], elem)
return ([lista[0]] + new_lista[0], new_lista[1])
# Exercicio 3.1
def cabeca(lista):
pass
return lista[0] if lista else None
# Exercicio 3.2
def cauda(lista):
pass
return lista[1:] if lista else []
# Exercicio 3.3
def juntar(l1, l2):
pass
if not l1 and not l2:
return []
if comprimento(l1) != comprimento(l2):
return None
jl = juntar(l1[1:], l2[1:])
return [(l1[0], l2[0])] + jl if jl is not None else None
# Exercicio 3.4
def menor(lista):
pass
if not lista:
return None
if len(lista) == 1:
return lista[0]
m = menor(lista[1:])
return lista[0] if lista[0] < m else m
# Exercicio 3.6
def max_min(lista):
pass
if not lista:
return None
if len(lista) == 1:
return (lista[0], lista[0])
mm = max_min(lista[1:])
return (lista[0] if lista[0] > mm[0] else mm[0], lista[0] if lista[0] < mm[1] else mm[1])