0

Hi, I have a question about lists and tables...

So far, i've managed to take a list and make a table like so:
23 764 12
54 83 2
543 890 1235
453 98

the list being [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98].

i need to change the code to produce a result looking like this:
23 54 543 453
764 83 890 98
12 2 1235

the code i have so far (to produce the first table) is this:

for i in range(0,len(list1),3):
    list2 = []
    list2.append(list1[i:i+3])
    for k in range(len(list2)):
        for j in range(len(list2[0])):
            print str(list2[k][j]).ljust(4),
        print

so you can see, i need to switch the rows and columns around...unfortunately....i'm not exactly sure how to go about doing that.

any help here?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by woooee
0

the list being [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98]

The easiest to understand is to use three new lists. In some kind of loop, append the first number to list1, the second to list2 and the third to list3. Rinse and repeat until the end. Then print the lists on separate lines.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.