I'm looking for a method of inserting values to 2D lists in Python. My sample list is as follows:
List= [ ['A', 'B'], ['C', 'D'] ]
I would like to insert a value at the beginning of each list within my List, so that it would look like this:
List = [ ['#','A', 'B'], ['#','C', 'D'] ]
I have written a function as follows:
def Foo(l):
rows = len(l)
cols = len(l[0])
for row in xrange(rows):
l.insert(row, '#')
But that has given me the following output:
List= [ '#', '#', ['A', 'B'], ['C', 'D'] ]
for row in l: row.insert(0, '#')