Dictionary Comprehension e Set Comprehension
This commit is contained in:
27
aula86.py
Normal file
27
aula86.py
Normal 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)
|
||||||
Reference in New Issue
Block a user