I need to be able to print at an offset where the second element of the second list matches up with the first element of the first list. For example have a's line up with the b's:

list = [[a, b, c, d],[a, X, X, b, c, d],[a, X, X, b, c, d],[a, b, c, d]]

a b c d
  a X X b c d
        a X X b c d 
              a b c d

I'm not looking for the answer. I am looking for people's thoughts/suggestions on how to go about this. Any help would be awesome.

Edited 7 Years Ago by nizbit: n/a

It is easier to code than to explain. This will only work if you use a fixed width font. A proportional font would require more work. It is a little bit tricky in that you want to print one sub-list based upon the "b" in the previous sub_list. I have chosen to look for "b" in this sub-list and print the next sub_list. Note that "list" is a reserved word in Python and should not be used as a variable name.

a = 'a'
b = 'b'
c = 'c'
d = 'd'
X = 'X'
lst = [[a, b, c, d],[a, X, X, b, c, d],[a, X, X, b, c, d],[a, b, c, d]]
spaces = ""
print "".join(lst[0])
## only process through the next to the last sub-list
## since we print the next sub-list
for ctr in range(0, len(lst)-1):
   sub_lst = lst[ctr]
   w_ctr = 0
   ##  look at each letter
   while (sub_lst[w_ctr] != b) and (w_ctr < len(sub_lst)):
      spaces += " "
      w_ctr += 1
   ##  prints the second through the last sub-list with spaces
   ##  from this list prepended
   print spaces + "".join(lst[ctr+1])

Edited 7 Years Ago by woooee: n/a

Thanks very much for the help. Now I'm going to study your example.

This article has been dead for over six months. Start a new discussion instead.