Entfernen des Zuletzt Eingefügten Elements in Python
Dictionaries verfügen außerdem über die Methode popitem(), die das letzte Schlüssel-Wert-Paar entfernt und zurückgibt.
12345678910111213book = { "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)
Aufgabe
Swipe to start coding
Gegeben ist das Dictionary authors_books.
- Entferne das letzte Element aus dem Dictionary.
- Füge ein neues Element mit dem Schlüssel
'Mark Twain'und dem Wert['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']hinzu. - Verwende die Methode
popitem(), um das letzte Element zu entfernen.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 15
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 4
Entfernen des Zuletzt Eingefügten Elements in Python
Swipe um das Menü anzuzeigen
Dictionaries verfügen außerdem über die Methode popitem(), die das letzte Schlüssel-Wert-Paar entfernt und zurückgibt.
12345678910111213book = { "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)
Aufgabe
Swipe to start coding
Gegeben ist das Dictionary authors_books.
- Entferne das letzte Element aus dem Dictionary.
- Füge ein neues Element mit dem Schlüssel
'Mark Twain'und dem Wert['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']hinzu. - Verwende die Methode
popitem(), um das letzte Element zu entfernen.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 15
single