Search code examples
pythonyfinance

How do I remove unwanted characters from a list created through python from yfinance?


I am pulling tickers from yfinance into a list and attempting to print the list. When printing, the list prints with characters added to each stock ticker. I would like to remove these characters and have tried using the lstrip and rstrip functions but I continue to get the added characters. Below is the input code:

for i in edited_buylist:
    i = str(i)
    i = i.lstrip('yfinance.Ticker object <')
for i in edited_buylist:
    i = str(i)
    i = i.rstrip('>')
print("The list of securities that are at or near support points are: ", str(edited_buylist))

Below is the output of that code:

The list of securities that are at or near support points are:  [yfinance.Ticker object <VVV>]

'''

I would like to remove the "yfinance.Ticker object<" and ">".


Solution

  • You can use the ticker attribute:

    edited_buylist = [i.ticker for i in edited_buylist]
    print("The list of securities that are at or near support points are: ", str(edited_buylist))