Calendar

Wednesday, August 10, 2011

For your own benefit. HTML Python code

def html(x):
    L = [ ]
    i = 0
    while i<len(x):
       
        if type(x[i])==type(x):
            if i == len(x) - 1 and type(x[0]) == type('abc'):
                L = L + html(x[i])
                start = x[0]
                m = '</'+start+'>'
                L.append(m)
            else:
                L = L + html(x[i])
           
        else:
            if i == 0:
                start = x[0]
                y = '<'+start+'>'
                L.append(y)
            elif i == len(x) - 1:
                L.append(x[i])
                z = '</'+start+'>'
                L.append(z)
            else:
                L.append(x[i])
        i= i+1
    return L
L = [['a',['f','g']],['b','c'],['d','e']]
for c in html(L):
    print c

No comments:

Post a Comment