def unpack_singleton(x):
    while isinstance(x, (list, tuple)):
        try:
            x = x[0]
        except (IndexError, TypeError, KeyError):
            break
    return x
>>> unpack_singleton([[[[1]]]])
dataset/ETHPy150Open dask/dask/dask/array/core.py/unpack_singleton