def get_stream_index(structure_pattern,structure_index):
    """
    Translates the sequence of indices identifying an item  in a hierarchy
    to the index identifying the same item in the flattened data stream.
    The structure indices must point to a value, not a list.
    >>> get_stream_index('..[[[.]..].].',[0])
    0
    >>> get_stream_index('..[[[.]..].].',[2,0,0,0])
    2
    >>> get_stream_index('..[[[.]..].].',[2,1])
    5
    """
    structure_index = list(structure_index)
    stream_index = 0 
    current_structure_index  = [0] 
    for p in structure_pattern:
        if p == '[':
            if current_structure_index >= structure_index:
                raise Exception('Provided structure_index does not point to a non-list element')
            current_structure_index.append(0)
        elif p == ']':
            if current_structure_index >= structure_index:
                raise Exception('Provided structure_index does not point to a non-list element')
            current_structure_index.pop(-1)
            current_structure_index[-1] += 1
        elif p == '.':
            if current_structure_index == structure_index:
                return stream_index
            stream_index += 1
            current_structure_index[-1] += 1
        else:
            raise Exception('Invalid character in structure pattern: %s' % repr(p))