def default(d, k, i, default=None):
    """Returns d[k][i], defaults to default if KeyError or IndexError is raised."""
    try:
        return d[k][i]
    except (KeyError, IndexError):
        return default