Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Eliminación del Último Elemento Insertado | Dominar los Diccionarios de Python
Estructuras de Datos en Python

Eliminación del Último Elemento Insertado

Los diccionarios también cuentan con el método popitem(), que elimina y devuelve el último par clave-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)
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 7
single

single

Eliminación del Último Elemento Insertado

Desliza para mostrar el menú

Los diccionarios también cuentan con el método popitem(), que elimina y devuelve el último par clave-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)
Tarea

Desliza para comenzar a programar

Se proporciona el diccionario authors_books.

  • Eliminar el último elemento del diccionario.
  • Agregar un nuevo elemento con la clave 'Mark Twain' y el valor ['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper'].
  • Utilizar el método popitem() para eliminar el último elemento.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 7
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt