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 | + | elif indent == lastIndent or indent == 0: |
15 | out.append(lines[at]) | |
16 | else: | |
17 | - | return at |
17 | + | return at - 1 |
18 | at = at + 1 | |
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 |