[英]How can I remove unwanted characters from a words list and put them cleared in another list using Python?
[英]How do I remove unwanted characters from a list created through python from yfinance?
我正在將 yfinance 的股票代碼拉入一個列表並嘗試打印該列表。 打印時,列表打印時會在每個股票代碼中添加字符。 我想刪除這些字符並嘗試使用lstrip
和rstrip
函數,但我繼續獲得添加的字符。 下面是輸入代碼:
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))
以下是該代碼的輸出:
The list of securities that are at or near support points are: [yfinance.Ticker object <VVV>]
'''
我想刪除“yfinance.Ticker 對象<”和“>”。
您可以使用ticker
屬性:
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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.