I have a list of stock tickers which I've scraped from the web and I'm trying to remove 'n/a' values from.
Here's a snippet of what the list looks like before trying to remove the values:
ticker_list = ['BANR',
'AUB',
'HOPE',
'INDB',
'CVBF',
'FFBC',
'FRME',
'TRMK',
'n/a',
'n/a']
So here is what I tried to run to remove those values:
for x in ticker_list:
if x == 'n/a':
ticker_list.remove(x)
This code partly works. It removes one of the n/a values, resulting in this:
['BANR',
'AUB',
'HOPE',
'INDB',
'CVBF',
'FFBC',
'FRME',
'TRMK',
'n/a']
I've also tried the following:
for x in ticker_list:
if x.strip() == 'n/a':
ticker_list.remove(x)
Also this:
for x in ticker_list:
if 'n/a' in x.strip():
ticker_list.remove(x)
In all cases, I get the same result. It removes just one of the n/a values, but one remains.
Is this some sort of encoding thing, or am I doing something dumb?
Thanks a lot for any responses!