I assume that you actually meant something like the comment of Tigerhawk.
Your problem is that e= (' ') , e is just overwriting the value of e (which was originally each value in your nested list) to a tuple containing a space and the original value. This doesnt actually change anything inside of your list, just changes whatever it is that e was originally pointing to.
You can instead do something like this:
>>> lin = [[2], [3], [2], [2, 2], [2]]
>>> for a in lin:
for i in range(len(a)-1,-1,-1):
a.insert(i, ' ')
>>> lin
[[' ', 2], [' ', 3], [' ', 2], [' ', 2, ' ', 2], [' ', 2]]
Note the inner loop: for i in range(len(a)-1,-1,-1): This is done this way because of 2 reasons:
- you dont want to be actually looping through
a since you are going to be changin the values in a
- You need to start with the highest index because if you start from 0, the indexes of the rest of the items ahead of it will change.
lin=[[' ',2], [' ',3], [' ',2], [' ',2, ' ',2], [' ',2]]?