Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Removendo o Último Item Inserido em Python | Seção
Estruturas de Dados em Python

bookRemovendo o Último Item Inserido em Python

Dicionários também possuem o método popitem(), que remove e retorna o último par chave-valor.

12345678910111213
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)
copy
Tarefa

Swipe to start coding

Você recebe o dicionário authors_books.

  • Remova o último elemento do dicionário.
  • Adicione 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'].
  • Utilize o método popitem() para remover o último elemento.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 15
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

close

bookRemovendo o Último Item Inserido em Python

Deslize para mostrar o menu

Dicionários também possuem o método popitem(), que remove e retorna o último par chave-valor.

12345678910111213
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)
copy
Tarefa

Swipe to start coding

Você recebe o dicionário authors_books.

  • Remova o último elemento do dicionário.
  • Adicione 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'].
  • Utilize o método popitem() para remover o último elemento.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 15
single

single

some-alt