Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countSpaces(str):
- for i in range(0, len(str)):
- if str[i] != ' ' and str[i] != '\t':
- return i
- return len(str)
- def addAll(lines, at, out, lastIndent):
- while at < len(lines):
- indent = countSpaces(lines[at])
- if indent > lastIndent:
- out.append(' ' * lastIndent + "{")
- at = addAll(lines, at, out, indent)
- out.append(' ' * lastIndent + "}")
- elif indent == lastIndent or indent == 0:
- out.append(lines[at])
- else:
- return at - 1
- at = at + 1
- return at
- lines = open('data.txt').read().split('\n');
- output = [];
- addAll(lines, 0, output, 0)
- for line in output:
- print line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement