Using the popitem() Method: Viimeksi Lisätyn Kohteen Poistaminen
Sanakirjoilla on myös popitem()
-menetelmä, joka poistaa ja palauttaa viimeisen avain-arvo-parin.
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)
Tehtävä
Swipe to start coding
Sinulle annetaan sanakirja authors_books
.
- Poista viimeinen elementti sanakirjasta.
- Lisää uusi elementti avaimella
'Mark Twain'
ja arvolla['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']
. - Käytä
popitem()
-menetelmää poistaaksesi viimeisen elementin.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 7
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 3.23
Using the popitem() Method: Viimeksi Lisätyn Kohteen Poistaminen
Pyyhkäise näyttääksesi valikon
Sanakirjoilla on myös popitem()
-menetelmä, joka poistaa ja palauttaa viimeisen avain-arvo-parin.
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)
Tehtävä
Swipe to start coding
Sinulle annetaan sanakirja authors_books
.
- Poista viimeinen elementti sanakirjasta.
- Lisää uusi elementti avaimella
'Mark Twain'
ja arvolla['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']
. - Käytä
popitem()
-menetelmää poistaaksesi viimeisen elementin.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Awesome!
Completion rate improved to 3.23Osio 2. Luku 7
single