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'}

7.5.4. Assignments

"""
* Assignment: Mapping Dict Pop
* Type: class assignment
* Complexity: easy
* Lines of code: 1 lines
* Time: 2 min

English:
    1. Use `DATA: dict`
    2. Define `result: str` with value popped for key 'group'
    3. Use `pop` method
    4. Run doctests - all must succeed

Polish:
    1. Użyj `DATA: dict`
    2. Zdefiniuj `result: str` z wartością dla klucza 'group'
    3. Użyj metodę `pop`
    4. Uruchom doctesty - wszystkie muszą się powieść

Hints:
    * dict.pop(key)

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert type(result) is str, \
    'Variable `result` has invalid type, should be str'

    >>> assert 'firstname' in DATA.keys()
    >>> assert 'lastname' in DATA.keys()
    >>> assert 'group' not in DATA.keys()

    >>> assert 'Mark' in DATA.values()
    >>> assert 'Watney' in DATA.values()
    >>> assert 'users' not in DATA.values()

    >>> pprint(result)
    'users'
"""

DATA = {
    'firstname': 'Mark',
    'lastname': 'Watney',
    'group': 'users',
}

# Define `result: str` with value popped for key 'group'
# Use `pop` method
# type: str
...

"""
* Assignment: Mapping Dict Clear
* Type: class assignment
* Complexity: easy
* Lines of code: 1 lines
* Time: 2 min

English:
    1. Use `DATA: dict`
    2. Define `result: None` with result of clearing all values
    3. Use `clear` method
    4. Run doctests - all must succeed

Polish:
    1. Użyj `DATA: dict`
    2. Zdefiniuj `result: None` z wynikiem wyczyszczenia wszystkich wartości
    3. Użyj metodę `clear`
    4. Uruchom doctesty - wszystkie muszą się powieść

Hints:
    * dict.clear()

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert result is None, \
    'Variable `result` has invalid type, should be dict'
    >>> assert type(DATA) is dict, \
    'Variable `DATA` has invalid type, should be dict'
    >>> assert DATA == {}, \
    'Variable `DATA` has not been cleared properly'

    >>> pprint(result)
    None
"""

DATA = {
    'firstname': 'Mark',
    'lastname': 'Watney',
    'group': 'users',
}

# Define `result: None` with result of clearing all values
# Use `clear` method
# type: None
result = ...