from collections.abc import Hashable


def get_nested(data, key, raise_on_error=True):
    if isinstance(key, Hashable):
        key = [key]
    v = data
    try:
        for k in key:
            v = v[k]
        return v
    except (TypeError, KeyError, IndexError) as e:
        if raise_on_error:
            raise e
        else:
            return None
