Parsing indented text and inserting its data into a tree
You should be able to accomplish this task by making one linear pass through the lines, instead of making one pass to build indents and a second pass to build entries.



It's good practice to package your code into functions, and to write docstrings for them.  In particular, if you have code that follows the pattern


outputs = []
for item in inputs:
    outputs.append(…)



… then consider writing a generator instead.



When you detect indentation that is not a multiple of 4 spaces, you print a message and stop building indents, but other than that, you still allow the program to proceed normally.  The program should probably abort at that point, and I suggest doing so by raising an exception.  Furthermore, I consider indentation that is suddenly excessively deep (e.g. going from 1 level to 3 levels of indentation) to be another kind of error that should be detected.



I don't like the way you handle the special case of the root node.  In particular, having a non-uniform tuple length is asking for trouble — it is basically data that is not of the same type.  I would avoid making the root node part of the data structure altogether, so that you don't have to write an exclusion for this special case:


for a in entries:
    if len (a) == 3: continue





Analyzing the text one character at a time (using while a[indent] == ' ': indent+=1) feels tedious.  I suggest using regular expressions to describe what kind of text you are expecting.  For example,

re.compile(r'^(?P&lt;indent&gt;(?: {4})*)(?P&lt;name&gt;\S.*)')


… says that you are looking for indentation at the beginning of the line that is a multiple of four spaces, followed by a name that starts with a non-space character.



Suggested solution

import re

def parse_tree(lines):
    """
    Parse an indented outline into (level, name, parent) tuples.  Each level
    of indentation is 4 spaces.
    """
    regex = re.compile(r'^(?P&lt;indent&gt;(?: {4})*)(?P&lt;name&gt;\S.*)')
    stack = []
    for line in lines:
        match = regex.match(line)
        if not match:
            raise ValueError(
                'Indentation not a multiple of 4 spaces: "{0}"'.format(line)
            )
        level = len(match.group('indent')) // 4
        if level &gt; len(stack):
            raise ValueError('Indentation too deep: "{0}"'.format(line))
        stack[level:] = [match.group('name')]
        yield level, match.group('name'), (stack[level - 1] if level else None)

raw = """…"""    
for level, name, parent in parse_tree(raw.split('\n')):
    print('{0}{1} ( {2} )'.format(' ' * (4 * level), name, parent or 'root'))