for key in enron_data.keys():
if(enron_data[key]['email_address'] != 'NaN'):
count += 1
print count
enron_data是2d字典,包含名称&价值,密钥对
答案 0 :(得分:1)
可以使用len(..)
len( [v for v in enron_data.values() if v['email_address'] != 'NaN'] )
答案 1 :(得分:0)
你可以试试这个:
print(sum(1 for key in enron_data.keys() if enron_data[key]["email_address"] != "NaN"))