Conteúdo do Curso
Estruturas de Dados em Python
Estruturas de Dados em Python
O Método Popitem()
Dicionários também têm um método popitem()
que remove e retorna o último par chave-valor.
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
Tarefa
Swipe to start coding
Você recebeu o dicionário authors_books
.
Seu objetivo:
- Remover o último elemento do dicionário.
- Adicionar um novo elemento com a chave
'Mark Twain'
e o valor['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']
. - Use o método
popitem()
para remover o último elemento.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 7
O Método Popitem()
Dicionários também têm um método popitem()
que remove e retorna o último par chave-valor.
book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Removing the last key-value pair using popitem() popped_item = book.popitem() # Printing the updated dictionary and the removed pair print("Removed item:", popped_item) print("Updated dictionary:", book)
Tarefa
Swipe to start coding
Você recebeu o dicionário authors_books
.
Seu objetivo:
- Remover o último elemento do dicionário.
- Adicionar um novo elemento com a chave
'Mark Twain'
e o valor['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']
. - Use o método
popitem()
para remover o último elemento.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 7