This code snippet is taken from the sample funadamental algo provided by Quantopian (https://www.quantopian.com/help#sample-live-trading).
# Find sectors with the highest average PE
sector_pe_dict = {}
for stock in fundamental_df:
sector = fundamental_df[stock]['morningstar_sector_code']
pe = fundamental_df[stock]['pe_ratio']
if sector in sector_pe_dict: # <----------------------- empty dictionary?
sector_pe_dict[sector].append(pe)
else:
sector_pe_dict[sector] = []
sector_pe_dict is initialized as an empty dictionary. In the for loop, the conditional stmt "if sector in sector_pe_dict" is testing an empty dictionary?