python - Printing a rather specific matrix -
i have list consisting of 148 entries. each entry 4 digit number. print out result this:
1 14 27 40 2 15 28 41 3 16 29 42 4 17 30 43 5 18 31 44 6 19 32 45 7 20 33 46 8 21 34 47 9 22 35 48 10 23 36 49 11 24 37 50 12 25 38 51 13 26 39 52 53 54 55... , on
i have code work first 13 rows , 4 columns:
kort_identifier = [my_list_with_the_entries] print_val = 0 print_num_1 = 0 print_num_2 = 13 print_num_3 = 26 print_num_4 = 39 while (print_val <= 36): print kort_identifier[print_num_1], '%10s' % kort_identifier[print_num_2], '%10s' % kort_identifier[print_num_3], '%10s' % kort_identifier[print_num_4] print_val += 1 print_num_1 += 1 print_num_2 += 1 print_num_3 += 1 print_num_4 += 1
i feel awful solution , there has better , simpler way of doing this. have searched through here (searched printing tables , matrices) , tried solution none seems work odd table/matrix behaviour need.
please point me in right direction.
a bit tricky, here go. opted manipulate list until had right shape, instead of messing around indexes.
lst = range(1, 149) lst = [lst[i:i+13] in xrange(0, len(lst), 13)] lst = zip(*[lst[i] + lst[i+4] + lst[i+8] in xrange(4)]) row in lst: col in row: print col, print
Comments
Post a Comment