如何从 yfinance python 创建的列表中删除不需要的字符?

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

我正在将代码从 yfinance 拉入列表并尝试打印列表。打印时,列表打印时每个股票代码都添加了字符。我想删除这些字符并尝试使用 lstriprstrip 函数,但我继续获取添加的字符。下面是输入代码:

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 object<" 和“>”。

您可以使用 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))