def popdefault(dictionary, key, default):
    """
    If the key is present and the value is not None, return it.
    If the key is present and the value is None, return ``default`` instead.
    If the key is not present, return ``default`` too.
    """
    value = dictionary.pop(key, None)
    return value or default