7.5. Mapping DelItem
7.5.1. Pop Method
>>> crew = {
... 'commander': 'Melissa Lewis',
... 'botanist': 'Mark Watney',
... 'pilot': 'Rick Martinez',
... 'chemist': 'Alex Vogel',
... 'surgeon': 'Chris Beck',
... 'engineer': 'Beth Johanssen',
... }
>>>
>>>
>>> left_alone_on_mars = crew.pop('botanist')
>>>
>>> print(left_alone_on_mars)
Mark Watney
>>>
>>> print(crew)
{'commander': 'Melissa Lewis',
'pilot': 'Rick Martinez',
'chemist': 'Alex Vogel',
'surgeon': 'Chris Beck',
'engineer': 'Beth Johanssen'}
7.5.2. Popitem Method
>>> crew = {
... 'commander': 'Melissa Lewis',
... 'botanist': 'Mark Watney',
... 'pilot': 'Rick Martinez',
... }
>>>
>>>
>>> last = crew.popitem()
>>>
>>> print(last)
('pilot', 'Rick Martinez')
>>>
>>> print(crew)
{'commander': 'Melissa Lewis', 'botanist': 'Mark Watney'}
7.5.3. Del Keyword
>>> crew = {
... 'commander': 'Melissa Lewis',
... 'botanist': 'Mark Watney',
... 'pilot': 'Rick Martinez',
... }
>>>
>>>
>>> del crew['pilot']
>>>
>>> print(crew)
{'commander': 'Melissa Lewis', 'botanist': 'Mark Watney'}