[Tutor] Matrix Transpose

G Kiran goki75 at vsnl.net
Fri Aug 29 19:43:03 EDT 2003


I was writing a small module to input a m x n matrix and print out the
transpose of it
how do i check if any of the rows has more elements  than others

if i have
1,2,3
1,2,3,4
4,5,6,7

i want

1,1,4
2,2,5
3,3,6
0,4,7

as  output
right now it only caters if in the input matrix
all rows have same no of elements

****i don't want to increase the prog size . my limit is the two lines

 my prog is


##########k=k=[ input() for i in range(input('Enter no of Rows:'))]
####Alternative input..for comma seperated values only

k=[[int(p) for p in raw_input(",").split()] for i in range(input('Enter no
of Rows:'))]
for a in [[k[x][y] for x in range(len(k))] for y in range(len(k[0]))]:print
a





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.509 / Virus Database: 306 - Release Date: 8/12/2003




More information about the Tutor mailing list