Python List Regex
I have a list from a stock web scraper looking like this: [......', 'xlnx>XLNX<', 'yhoo>YHOO<']
how can I get the dictionary with only the quotes? I know this is simple but I could use some help. Thanks
import urllib import re base_url = 'http://www.nasdaq.com/markets/indices/nasdaq-100.aspx' content = urllib.urlopen(base_url).read() list = re.findall('http://www.nasdaq.com/symbol/(.*)/a>', content) print list
You have a list, not a dictionary. Also you shouldn't name your variable list as it is the name of a built-in.
>>> content ['xlnx>XLNX<', 'yhoo>YHOO<'] >>> tickers =  >>> for s in content: ... tickers.append(''.join(i for i in s if i.isupper())) ... >>> tickers ['XLNX', 'YHOO']