I want to remove the letters from row[1] and row[2] or if they are empty put None. The loop places None works fine but when it get to the other loop if it encounters a None I get the error. How can I fix it? Thanks in advance!
a = [['something', 'G3535354', '33453421D'], ['something', '', 'R3848347']]
i = 0
char_no = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for row in a:
j = 0
for col in row:
if a[i][j] == '':
a[i][j] = None
j += 1
for character in char_no:
row[1] = row[1].replace(character, "")
row[2] = row[2].replace(character, "")
i += 1
print(a)
enumerate. That avoids using extra lines such asi = 0,i += 1etc.None, it's not a string anymore. In the next loop, however, you use a string method on that element, namely,.replace(). So you'd getNone.replace(character, ""). That will obviously fail.None.