def transpose(matrix):
#FOLLOWING is my code, it is incorrect however. COULD ANY GIVE ME A HAND?
O(∩_∩)OThanks :)
l=len(matrix)
i=0
j=0
Aj=[]
T=[]
for i in range(l):
Ai=matrix
li=len(Ai)
i+=1
for j in range(li):
Aij=Ai[j]
j+=1
for i in range(l):
Aj.append(Aij)
i+=1
for j in range(li):
T.append(Aj)
j+=1
return T

I've added some notes on what is and is not happening. When you don't understand something it is usually good to break it into smaller pieces and solve each piece individually. This code is not even good enough to correct so start again and post back, next time include an input and desired output example as well, to make sure everyone is using the same definition for 'transposition'.

def transpose(matrix):
    l=len(matrix)
    i=0
    j=0
    Aj=[]
    T=[]
    for i in range(l):         ## is this range one or range el?
        Ai=matrix[i]           ## Ai will always contain the last matrix value
        print "Ai =", Ai       ## print to show each value is overwritten by the next
        li=len(Ai)
        i+=1                   ## this "i" variable does nothing and can be deleted
        for j in range(li):
            Aij=Ai[j]          ## will always contain last value in the range
            j+=1               ## does nothing and can be deleted
    for i in range(l): 
     Aj.append(Aij)            ## continuously appends the same value = Aij
     i+=1                      ## does nothing so can be deleted
    for j in range(li):
     T.append(Aj)              ## continuously appends the same value = Aj
    return T

'matrix is a list of lists of the same size to
emulate a mathematical matrix:

matrix = [
[1, 2, 3],
[4, 5, 6]
],

So the i^th list in matrix is the i^th row of matrix.
This function will compute the transpose of the matrix.

After a transposition, the original element in row i and
column j will end up to be in row j and column i.


Return: the transposed matrix as a list of lists.'''

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.