I would have a huge list of Nasdaq stocks defined as a variable. Here's the code:
from ftplib import FTP
def my_function(data):
print(data.decode())
ftp = FTP('ftp.nasdaqtrader.com')
ftp.login()
nasdaq=ftp.retrbinary('RETR /SymbolDirectory/nasdaqlisted.txt', my_function)
If I print out the string "nasdaq" I can see it comes in the following format:
AAAP|Advanced Accelerator Applications S.A. - American Depositary Shares|Q|N|N|100|N|N
AAL|American Airlines Group, Inc. - Common Stock|Q|N|N|100|N|N
AAME|Atlantic American Corporation - Common Stock|G|N|N|100|N|N
AAOI|Applied Optoelectronics, Inc. - Common Stock|G|N|N|100|N|N
and so on...
I want a list where only the tickers are printed out:
AAAP
AAL
AAME
AAOI
What is the right approach to do this?