0

I am trying to remove an item from a list, the code looks like:

s = []
full_c = ['0','1','2','3','4','5','6','7','8','9']

for i in range(5):
    s.append(full_c)

try:
    s[2].remove('1')
except:
    pass

print(*s,sep="\n")

Here I intend to remove the item '1' from the third row alone.

The result is:

['0', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '2', '3', '4', '5', '6', '7', '8', '9']
['0', '2', '3', '4', '5', '6', '7', '8', '9']

Why the specific item is removed from every list (within the main list)? How to remove only one entry from the third row alone?

0 Answers0