popitem() method is used to remove the last inserted element in a dictionary and return that element as a tuple.
popitem() method does not require any parameters. In addition, it returns the value that was removed from the dictionary as a key:value pair in a tuple.
postcodes = dict(griffith=2603, belconnen=2617, phillip=2606) last_item = postcodes.popitem() print(postcodes) print(last_item)
View all Courses