def CollapsePath(path_tokens):
    """
    CollapsePath() takes a list of Strings argument representing a
    directory-like path string
    (for example '/SUB1A/Sub2A/../Sub2B/sub3b/../sub3c/entry'),
    and replaces it with a version which should contain no '..' patterns.
    (In the example above, it returns /SUB1A/Sub2B/sub3c/entry')
    """
    new_ptkns = []
    ndelete = 0
    i = len(path_tokens) - 1
    while i >= 0:
        if path_tokens[i] == '..':
            ndelete += 1
        else:
            if (ndelete > 0) and (path_tokens[i] != ''):
                # Note: "path_tokens[i] != '')"  means "/a/b//c" <-> "/a/b/c"
                ndelete -= 1
            else:
                if len(path_tokens[i]) > 0:
                    new_ptkns.append(path_tokens[i])
        i -= 1
    new_ptkns.reverse()

    if ndelete > 0:
        return ndelete  # <-- useful to let caller know an error ocurred

    return new_ptkns