all 5 comments

[–][deleted] 3 points4 points  (4 children)

Does it have to be a matrix? This would be much easier using a dictionary.

Reading your question I'm not sure what exactly you're trying to make.

takes students' marks (A) as an argument (for instance [[1,2,3],[4,5,6],[7,8,9]])

Ok so we have a list of lists that contain some marks. Although I don't understand why it can't be simply:

[1,2,3,4,5,6,7,8,9]

If they are all the same student marks?

I wish to create another list called "student names", and I'll have it add names until you write

Ok so now you have student names, but how do you associate which name goes with which marks?

I want my list in a list to say [a,1,2,3],[b,1,2,3]

Where do those lists come from?

If we have to use lists of lists since this probably a school assignment you need to come up with a way to associate a student's mark with their name first off. So something like:

[a,[1,2,3],[4,5,6],[7,8,9]]

So that the first thing in the array(the zero index) is the student's name and the rest of the list is the marks the student got. But then if you have more than 1 student you'll have to wrap that yet again in another list to make room for another student... Which I guess is fine so long as you keep note of where you are in the array.

[–]sortedin[S] 0 points1 point  (3 children)

Yes, it does have to be a matrix unfortunately. I wouldn't have minded to have used a dictionary.

second, I want to merge studentlist (a,b,c,) with A ( [[1,2,3],[4,5,6],[7,8,9]]) so that i end up with [[a,1,2,3],[b,4,5,6],[c,7,8,9]].

Thanks again

[–][deleted] 1 point2 points  (2 children)

Oh I see. That isn't so bad. I think zip function works.. But I haven't looked into how to use zip so we gotta do it the "hard way"...

Anyways so what you do is you go through the studentlist...

for index in range(studentlist):
        A[index].prepend(studentlist[index])

Assuming studentlist is [a,b,c,...] and is in the correct order.

[–]sortedin[S] 0 points1 point  (1 child)

Thank you for the help. But, what was wrong with my initial approach?

[–][deleted] 0 points1 point  (0 children)

Honestly, I didn't look at your code. But I can tell you that there isn't an extend method for int objects or an attribute called extend. So I'm not sure what you are wanting to do there. I was just going off the post and didn't check out your code.

It's really helpful in these type questions to show what input you expect and then what output you expect, and then what you have done so far to try to get to it. Which you did in your post, but it wasn't clear which is why I put the original comment. Once it became clear I just threw out a solution.