I\'m a beginner programmer so this question might sound trivial: I have some text files containg tab-delimited text like:
A
B
C
D
E
<
Try this (works on your test case):
import itertools
def listify(filepath):
depth = 0
print ""*(depth+1)
for line in open(filepath):
line = line.rstrip()
newDepth = sum(1 for i in itertools.takewhile(lambda c: c=='\t', line))
if newDepth > depth:
print ""*(newDepth-depth)
elif depth > newDepth:
print "
"*(depth-newDepth)
print "- %s
" %(line.strip())
depth = newDepth
print "
"*(depth+1)
Hope this helps