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

Reply via email to