Mega Code Archive

 
Categories / Python / Dictionary
 

Dictionary popitem

#The popitem method is similar to list.pop. Unlike list.pop, however, popitem pops  #off a random item because dictionaries don't have a "last element" or any order  #whatsoever. This may be very useful if you want to remove and process the items one  #by one in an efficient way (without retrieving a list of the keys first): d = {'url': 'http://www.python.org', 'spam': 0, 'title': 'Python Web Site'} print d.popitem() print d #Although popitem is similar to the list method pop, there is no dictionary  #equivalent of append. Because dictionaries have no order, such a method wouldn't  #make any sense.