Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

regex - How to validate if text is a stock ticker in python

I'm trying to find an efficient way of validating if each element in a list is a stock ticker. The code below works but its too slow I'm looking for a faster way, Thanks in advance I can clarify anything if needed

tickers_post = re.findall("[A-Z]{3,4}", str(post))  # RegEx to extract tickers from a list

def tickerData(tic):
    yf.Ticker(tic).info

count = len(tickers_post) -1

while count >= 0:
    try:
        tickerData(str(tickers_post[count]))

    except:
        print('Not a ticker:' + tickers_post[count])
        tickers_post.pop(count)
    count = count - 1

Print(ticker_post)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...