2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.1
|
2024-09-17 10:51:44 +00:00
|
|
|
def comprimento(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
return comprimento(lista[1:]) + 1 if lista else 0
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 1.2
|
2024-09-17 10:51:44 +00:00
|
|
|
def soma(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
return soma(lista[1:]) + lista[0] if lista else 0
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.3
|
2024-09-17 10:51:44 +00:00
|
|
|
def existe(lista, elem):
|
2024-09-23 10:09:56 +00:00
|
|
|
return False if not lista else (
|
|
|
|
True if lista[0] == elem else existe(lista[1:], elem))
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.4
|
2024-09-17 10:51:44 +00:00
|
|
|
def concat(l1, l2):
|
2024-09-23 10:09:56 +00:00
|
|
|
return l1 if not l2 else concat(l1 + [l2[0]], l2[1:])
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 1.5
|
2024-09-17 10:51:44 +00:00
|
|
|
def inverte(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
return [lista[-1]] + inverte(lista[:-1]) if lista else []
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.6
|
2024-09-17 10:51:44 +00:00
|
|
|
def capicua(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
return lista[0] == lista[-1] and capicua(lista[1:-1]) if lista else True
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.7
|
2024-09-17 10:51:44 +00:00
|
|
|
def concat_listas(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
return lista[0] + concat_listas(lista[1:]) if lista else []
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 1.8
|
2024-09-17 10:51:44 +00:00
|
|
|
def substitui(lista, original, novo):
|
2024-09-23 10:09:56 +00:00
|
|
|
if not lista:
|
|
|
|
return []
|
|
|
|
if lista[0] == original:
|
|
|
|
lista[0] = novo
|
|
|
|
return [lista[0]] + substitui(lista[1:], original, novo)
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.9
|
2024-09-17 10:51:44 +00:00
|
|
|
def fusao_ordenada(lista1, lista2):
|
2024-09-23 10:09:56 +00:00
|
|
|
if not lista1:
|
|
|
|
return lista2
|
|
|
|
if not lista2:
|
|
|
|
return lista1
|
|
|
|
if lista1[0] < lista2[0]:
|
|
|
|
return [lista1[0]] + fusao_ordenada(lista1[1:], lista2)
|
|
|
|
return [lista2[0]] + fusao_ordenada(lista1, lista2[1:])
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 1.10
|
2024-09-17 10:51:44 +00:00
|
|
|
def lista_subconjuntos(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
if not lista:
|
|
|
|
return [[]]
|
|
|
|
return lista_subconjuntos(lista[1:]) + [lista[:1] + x for x in lista_subconjuntos(lista[1:])]
|
2024-09-17 10:51:44 +00:00
|
|
|
|
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 2.1
|
2024-09-17 10:51:44 +00:00
|
|
|
def separar(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 2.2
|
2024-09-17 10:51:44 +00:00
|
|
|
def remove_e_conta(lista, elem):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|
|
|
|
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
# Exercicio 3.1
|
2024-09-17 10:51:44 +00:00
|
|
|
def cabeca(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 3.2
|
2024-09-17 10:51:44 +00:00
|
|
|
def cauda(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 3.3
|
2024-09-17 10:51:44 +00:00
|
|
|
def juntar(l1, l2):
|
|
|
|
pass
|
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 3.4
|
2024-09-17 10:51:44 +00:00
|
|
|
def menor(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|
2024-09-17 10:51:44 +00:00
|
|
|
|
2024-09-23 10:09:56 +00:00
|
|
|
|
|
|
|
# Exercicio 3.6
|
2024-09-17 10:51:44 +00:00
|
|
|
def max_min(lista):
|
2024-09-23 10:09:56 +00:00
|
|
|
pass
|