def get(l, i, d=None):
    """Returns the value of l[i] if possible, otherwise d."""
    
    if type(l) in (dict, set):
        return l[i] if i in l else d
    
    try:
        return l[i]
    except (IndexError, KeyError, TypeError):
        return d