def simplifyPath(self, path):
        path = path.split("/")
        path = filter(lambda x: x not in ("", " ", "."), path)

        # modify the content of the list, not the structure.
        for idx in xrange(len(path)):
            val = path[idx]
            if val == "..":
                path[idx] = "."

                # rm a previous meaningful part
                i = idx-1
                while i >= 0 and path[i] == ".": i -= 1
                if i >= 0: path[i] = "."  # avoid path[-1]

        path = filter(lambda x: x not in (".",), path)

        if not path:
            return "/"

        path = map(lambda x: "/"+x, path)
        return "".join(path)
use "." as intermediate
dataset/ETHPy150Open algorhythms/LeetCode/068 Simplify Path.py/Solution.simplifyPath