Thanks that works! But what if I wanted to modify 2 of the three lists in 2 different positions? Could you please let me know how I would go about doing that?
Thanks! -Raj ________________________________ From: Ken Oliver <ksterl...@mindspring.com> To: Raj Medhekar <cosmicsan...@yahoo.com>; Python Tutor <tutor@python.org> Sent: Sunday, July 19, 2009 8:16:11 PM Subject: Re: [Tutor] Using insert method on a list matrix try M[0].insert(0, 'pod') -----Original Message----- > >From: Raj Medhekar > >Sent: Jul 19, 2009 7:12 PM > >To: Python Tutor > >Subject: [Tutor] Using insert method on a list matrix > > > > >I would like to know how I could use the insert method in a List matrix eg. >for the matrix below > >M=[[1,2,3], [3,2,1], [4,3,2]] > >if wanted to insert the string 'pod' in list [0] before [1] in list [0] in M >using the built in method insert How would I go about doing this? I've tried >may List Comprehension possibilities but none of then worked. Below are some >of the things I tried. > >>>> M=[[1,2,3], [3,2,1], [4,3,2]] >>>> M.insert([1][1], 'pod') > >Traceback (most recent call last): > File "<pyshell#19>", line 1, in <module> > M.insert([1][1], 'pod') >IndexError: list index out of range >>>> [row[0] for row in M.insert(1, 'pod')] > >Traceback (most recent call last): > File > "<pyshell#20>", line 1, in <module> > [row[0] for row in M.insert(1, 'pod')] >TypeError: 'NoneType' object is not iterable >>>> M.insert(1,'pod') >>>> M >[[1, 2, 3], 'pod', 'pod', [3, 2, 1], [4, 3, 2]] >>>> M.insert[0](1,'pod') > >Traceback (most recent call last): > File "<pyshell#23>", line 1, in <module> > M.insert[0](1,'pod') >TypeError: 'builtin_function_or_method' object is unsubscriptable > > >Any help is greatly appreciated! Thanks! > >-Raj > > .
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor