1
resposta

[Hora da prática]: dicionários

pessoa = {'nome': 'Lana', 'idade': 75, 'cidade':'Catuaba'}
print(pessoa)

pessoa.update({'idade': 20})
pessoa['profissao'] = 'Agiota'
del pessoa['cidade']
print(pessoa)

print({x: x**2 for x in range(1,6)})

print('Existe no dicionário' if pessoa['nome'] else 'Inexistente no dicionário')

zen_python = '''
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''

contar = {}
palavras = zen_python.split()
for palavra in palavras: 
    contar[palavra] = contar.get(palavra, 0) + 1
print(contar)

Matricule-se agora e aproveite até 50% OFF

O maior desconto do ano para você evoluir com a maior escola de tecnologia

QUERO APROVEITAR
1 resposta

Ei! Tudo bem?

Seu código está muito bom, demonstrando domínio sobre manipulação e construção eficiente de dicionários em Python, o que é uma skill essencial para qualquer projeto nessa área.

Parabéns pelo trabalho! Se tiver mais dúvidas, compartilhe no fórum.

Alura Conte com o apoio da comunidade Alura na sua jornada. Abraços e bons estudos!