セクション 2. 章 7
single
popitem() メソッドの使用:最後に挿入された項目の削除
メニューを表示するにはスワイプしてください
辞書には、最後に追加されたキーと値のペアを削除して返す popitem() メソッドも存在。
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)
タスク
スワイプしてコーディングを開始
辞書 authors_books が与えられています。
- 辞書から最後の要素を削除してください。
- キー
'Mark Twain'と値['The Adventures of Tom Sawyer', 'Adventures of Huckleberry Finn', 'The Prince and the Pauper']を持つ新しい要素を追加してください。 - 最後の要素を削除するには
popitem()メソッドを使用してください。
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 2. 章 7
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください