Python‎ > ‎dict‎ > ‎

dict.popitem()

http://www.adilwaseem.com/

Introduction
Remove and return with the dictionary.

Syntax
dict.popitem()

Parameters
None

Examples
The method remove and return with the dictionary values.
 >>> x=dict({'VA':3.1, 'DC':2,'NY':5.1, 'CA':4.4})
>>> x.popitem()
('VA', 3.1)
>>> x
{'DC': 2, 'NY': 5.1, 'CA': 4.4}
>>> x.popitem()
('DC', 2)
>>> x
{'NY': 5.1, 'CA': 4.4}
>>> x.popitem()
('NY', 5.1)
>>> x
{'CA': 4.4}
>>> x.popitem()
('CA', 4.4)
>>> x
{}
>>>

The method remove from the dictionary.
 >>> 
>>> a=dict({'Din': 4, 'John': 2, 'Adil': 3, 'Fen': 1})
>>> a.popitem()
('Din', 4)
>>> a
{'John': 2, 'Adil': 3, 'Fen': 1}
>>> a.popitem()
('John', 2)
>>> a
{'Adil': 3, 'Fen': 1}
>>> a.popitem()
('Adil', 3)
>>> a
{'Fen': 1}
>>>

Comments