def g(s,c):x=s.split('|');print' #\n'.join(' '*len(''.join(x[:i]))+v+' '*len(''.join(x[i+1:]))for i,v in enumerate(x))+' '+c for s, c in (("a|b|c|d|e|f|g", ","),("abcdefg", ":"),("4|8|15|16|23|42", "%"),("E|ac|h s|ecti|on is| one c|haracte|r longer| than the| last!", "!"),("This|Code|has||empty||sections", "@")): print'Input:\n',(s,c),'\n\nOutput:' g(s,c) print''