def itemgetter_with_default(default, attr):
    """Retrieves a dictionary entry by its key `attr`. Returns `default` if the key is not there.

    >>> itemgetter_with_default(0, "a")({"a": 1})
    1
    >>> itemgetter_with_default(0, "b")({"a": 1})
    0
    """

    def itemgetter_with_default(d):
        try:
            return d[attr]
        except (KeyError, IndexError):
            return default

    return itemgetter_with_default