简体   繁体   中英

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 ">".

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM