Dictionary Comprehension e Set Comprehension

This commit is contained in:
Luiz Otávio
2022-11-03 13:01:38 -03:00
parent 348c9b4e59
commit 1fd6ee1793

27
aula86.py Normal file
View File

@@ -0,0 +1,27 @@
# Dictionary Comprehension e Set Comprehension
produto = {
'nome': 'Caneta Azul',
'preco': 2.5,
'categoria': 'Escritório',
}
dc = {
chave: valor.upper()
if isinstance(valor, str) else valor
for chave, valor
in produto.items()
if chave != 'categoria'
}
lista = [
('a', 'valor a'),
('b', 'valor a'),
('b', 'valor a'),
]
dc = {
chave: valor
for chave, valor in lista
}
s1 = {2 ** i for i in range(10)}
print(s1)