'Conveting MutableDenseNDimArray to one-dim list
Examples
>>> from sympy import MutableDenseNDimArray
>>> a = MutableDenseNDimArray([1, 2, 3, 4], (2, 2))
>>> a
[[1, 2], [3, 4]]
>>> b = a.tolist()
>>> b
[[1, 2], [3, 4]]'

def tolist(self):

    def f(sh, shape_left, i, j):
        if (len(shape_left) == 1):
            return [self[e] for e in range(i, j)]
        result = []
        sh //= shape_left[0]
        for e in range(shape_left[0]):
            result.append(f(sh, shape_left[1:], (i + (e * sh)), (i + ((e + 1) * sh))))
        return result
    return f(self._loop_size, self.shape, 0, self._loop_size)
