def poiFlagEmail(f): """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### poi_emails.poiEmails() returns a list of all POIs' email addresses. poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False if to_emails: ctr = 0 while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not cc_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 if from_emails: ctr = 0 while not from_poi and ctr < len(from_emails): if from_emails[ctr] in poi_email_list: from_poi = True ctr += 1 return to_poi, from_poi, cc_poi
def poiFlagEmail(f): """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### poi_emails.poiEmails() returns a list of all POIs' email addresses. poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False ### to_poi and cc_poi are related functions, which flag whether ### the email under inspection is addressed to a POI, or if a POI is in cc ### you don't have to change this code at all ### there can be many "to" emails, but only one "from", so the ### "to" processing needs to be a little more complicated # uses counter for iteration, duplicates process for cc_emails # does not seem very pythonic, but maybe clearest method if to_emails: ctr = 0 # counter for iterating through, perhaps not pythonic while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not to_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 ################################# ######## your code below ######## ### set from_poi to True if ##### ### the email is from a POI ##### ################################# # initial difficulty getting correct output because I was not # I had from_email in... instead of from_emails[0] in... # (needs item index for list, even though only one item in list) assert len(from_emails) == 1 from_poi = True if from_emails[0] in poi_email_list else False # assert from_emails == True # if from_emails: # if from_emails[0] in poi_email_list: # from_poi = True ################################# return to_poi, from_poi, cc_poi
def poiFlagEmail(f): #print "poiFlagEmail started" """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### poi_emails.poiEmails() returns a list of all POIs' email addresses. poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False #print "to_emails:",to_emails ### to_poi and cc_poi are related functions, which flag whether ### the email under inspection is addressed to a POI, or if a POI is in cc ### you don't have to change this code at all ### there can be many "to" emails, but only one "from", so the ### "to" processing needs to be a little more complicated if to_emails: ctr = 0 while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not to_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 ################################# ######## your code below ######## ### set from_poi to True if ##### ### the email is from a POI ##### ################################# #create the numpy array of the poi_emails_list import numpy as np poi_email_arr = np.array(poi_email_list) #check if from_email is in poi_emails_list from_poi = True in np.in1d(poi_email_arr, np.array(from_emails)) #check if to_email is in poi_emails_list to_poi = True in np.in1d(poi_email_arr, np.array(to_emails)) #check if cc_email is in poi_emails_list cc_poi = True in np.in1d(poi_email_arr, np.array(cc_emails)) #NOTE: if the in command gives error then check if cc_emails is none before doing it because some emails dont have ccs print "poi_emails_arr:", poi_email_arr print "from_emails:",from_emails print "to_emails:",to_emails print "cc_emails:",cc_emails print from_poi,to_poi,cc_poi ################################# return to_poi, from_poi, cc_poi
def poiFlagEmail(f): """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### poi_emails.poiEmails() returns a list of all POIs' email addresses. poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False ### to_poi and cc_poi are related functions, which flag whether ### the email under inspection is addressed to a POI, or if a POI is in cc ### you don't have to change this code at all ### there can be many "to" emails, but only one "from", so the ### "to" processing needs to be a little more complicated if to_emails: ctr = 0 while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not to_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 ################################# ######## your code below ######## ### set from_poi to True if ##### ### the email is from a POI ##### ################################# if from_emails: ctr=0 while not from_poi and ctr<len(from_emails): if from_emails[ctr] in poi_email_list: from_poi=True ctr+=1 return to_poi,from_poi,cc_poi ################################# return to_poi, from_poi, cc_poi
def poiFlagEmail(f): """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### list of email addresses of all the POIs poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False ### to_poi and cc_poi are related functions, which flag whether ### the email under inspection is addressed to a POI, or if a POI is in cc ### you don't have to change this code at all ### there can be many "to" emails, but only one "from", so the ### "to" processing needs to be a little more complicated if to_emails: ctr = 0 while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not to_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 if from_emails: ctr = 0 while not from_poi and ctr < len(from_emails): if from_emails[ctr] in poi_email_list: from_poi = True ctr += 1 ################################# ######## your code below ######## ### set from_poi to True if ##### ### the email is from a POI ##### ################################# ################################# return to_poi, from_poi, cc_poi
def poiFlagEmail(f): """ given an email file f, return a trio of booleans for whether that email is to, from, or cc'ing a poi """ to_emails, from_emails, cc_emails = getToFromStrings(f) ### poi_emails.poiEmails() returns a list of all POIs' email addresses. poi_email_list = poi_emails.poiEmails() to_poi = False from_poi = False cc_poi = False ### to_poi and cc_poi are boolean variables which flag whether the email ### under inspection is addressed to a POI, or if a POI is in cc, ### respectively. You don't have to change this code at all. ### There can be many "to" emails, but only one "from", so the ### "to" processing needs to be a little more complicated if to_emails: ctr = 0 while not to_poi and ctr < len(to_emails): if to_emails[ctr] in poi_email_list: to_poi = True ctr += 1 if cc_emails: ctr = 0 while not cc_poi and ctr < len(cc_emails): if cc_emails[ctr] in poi_email_list: cc_poi = True ctr += 1 ################################# ######## your code below ######## ### set from_poi to True if ##### ### the email is from a POI ##### ################################# if from_emails: ctr = 0 while not from_poi and ctr < len(from_emails): if from_emails[ctr] in poi_email_list: from_poi = True ctr += 1 # print to_poi, from_poi, cc_poi # used a print statement to test the code ################################# return to_poi, from_poi, cc_poi