I have two problem with this code. First, it doesn't remove the '\n' at the end of the list row. So I tried printing x to see what is going on but then I ran into the second issue which is that x doesn't get printed. It seems that some line breaks and '51' gets printed, but why only those but not others?
How can this happen? I have absolutely no clue.
Edit: This is NOT a duplicate. I want to know why it doesn't remove but ALSO why it doesn't print. @Aran-Fey Read the question before you mark it as duplicate.
row = ['\n', '2017-18 ', '\n', 'GSW', '\n', '\n', '51', '\n', '32.0', '\n', '26.4', '\n', '8.4', '\n', '16.9', '\n', '49.5', '\n', '4.2', '\n', '9.8', '\n', '42.3', '\n', '5.5', '\n', '5.9', '\n', '92.1', '\n', '0.7', '\n', '4.4', '\n', '5.1', '\n', '6.1', '\n', '3.0', '\n', '1.6', '\n', '0.2', '\n', '2.2', '\n', '43.8', '\n', '5', '\n', '0', '\n', '9.5', '\n']
i = 0
for x in row:
print(i,":", x)
if x in ('\n', '°', '%'):
row.remove(x)
i+=1
print(row)
The output of this is
0 :
1 :
2 :
3 : 51
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 :
12 :
13 :
14 :
15 :
16 :
17 :
18 :
19 :
20 :
21 :
22 :
23 :
24 :
25 :
26 :
27 :
['2017-18 ', 'GSW', '51', '32.0', '26.4', '8.4', '16.9', '49.5', '4.2', '9.8', '42.3', '5.5', '5.9', '92.1', '0.7', '4.4', '5.1', '6.1', '3.0', '1.6', '0.2', '2.2', '43.8', '5', '0', '9.5', '\n']
You can run this code here: https://repl.it/@leonardchoo/listnotworking