View difference between Paste ID: F91eyY34 and nBtU9PPw
SHOW: | | - or go back to the newest paste.
1
def countSpaces(str):
2
    for i in range(0, len(str)):
3
        if str[i] != ' ' and str[i] != '\t':
4
            return i
5
    return len(str)
6
7
def addAll(lines, at, out, lastIndent):
8
    while at < len(lines):
9
        indent = countSpaces(lines[at])
10
        if indent > lastIndent:
11
            out.append(' ' * lastIndent + "{")
12
            at = addAll(lines, at, out, indent)
13
            out.append(' ' * lastIndent + "}")
14-
        elif indent == lastIndent:
14+
            at = at + 1
15
        elif indent == lastIndent or indent == 0:
16
            out.append(lines[at])
17
        else:
18-
        at = at + 1
18+
19
    return at
20
21
lines = open('data.txt').read().split('\n');
22
output = [];
23
addAll(lines, 0, output, 0)
24
for line in output:
25
    print line