-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncao_lambda.py
More file actions
36 lines (31 loc) · 1.04 KB
/
Copy pathfuncao_lambda.py
File metadata and controls
36 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Introdução à função lambda (função anônima de uma linha)
# A função lambda é uma função como qualquer
# outra em Python. Porém, são funções anônimas
# que contém apenas uma linha. Ou seja, tudo
# deve ser contido dentro de uma única
# expressão.
# lista = [
# {'nome': 'Luiz', 'sobrenome': 'miranda'},
# {'nome': 'Maria', 'sobrenome': 'Oliveira'},
# {'nome': 'Daniel', 'sobrenome': 'Silva'},
# {'nome': 'Eduardo', 'sobrenome': 'Moreira'},
# {'nome': 'Aline', 'sobrenome': 'Souza'},
# ]
# lista = [4, 32, 1, 34, 5, 6, 6, 21, ]
# lista.sort(reverse=True)
# sorted(lista)
lista = [
{'nome': 'Luiz', 'sobrenome': 'miranda'},
{'nome': 'Maria', 'sobrenome': 'Oliveira'},
{'nome': 'Daniel', 'sobrenome': 'Silva'},
{'nome': 'Eduardo', 'sobrenome': 'Moreira'},
{'nome': 'Aline', 'sobrenome': 'Souza'},
]
def exibir(lista):
for item in lista:
print(item)
print()
l1 = sorted(lista, key=lambda item: item['nome'])
l2 = sorted(lista, key=lambda item: item['sobrenome'])
exibir(l1)
exibir(l2)