Solved! Go to Solution.
# fix date, returns a dictionary with sortable values def FixDate(in_date): month_dict = {'Jan':'01','Feb':'02','Mar':'03','Apr':'04', 'May':'05','Jun':'06','Jul':'07','Aug':'08', 'Sep':'09','Oct':'10','Nov':'11','Dec':'12'} # split date string by space and remove comma in_date_items = in_date.replace(',','').split() # separate year,month,day year = in_date_items[-1] month = month_dict[in_date_items[0]] day = in_date_items[1].zfill(2) # sort date dictionary sort_dict = {} sort_dict[in_date] = '/'.join([year,month,day]) return sort_dict # your dictionary of applicants apps = {'Smith, John':[['Smith, John', 'Jan 10, 2013', 'Applied'], ['Smith, John', 'Feb 3, 2013' 'Assigned'], ['Smith, John', 'Mar 25, 2013', 'Tested'], ['Smith, John', 'Jun 11, 2013', 'Hired']], 'Smith, Jack':[['Smith, Jack', 'Jan 10, 2013', 'Applied'], ['Smith, Jack', 'Feb 7, 2013', 'Assigned'], ['Smith, Jack', 'Mar 25, 2013', 'Tested'], ['Smith, Jack', 'Jun 5, 2013', 'Rejected']], 'Smith, Kim':[['Smith, Kim', 'Jan 10, 2013', 'Applied'], ['Smith, Kim', 'Feb 12, 2013', 'Rejected']]} # return most recent action for each person action_dict = {} for name, info in apps.iteritems(): #iterates through each list of actions to find most recent action for details in info: dates = {} dates[details[1]] = details[-1] recent = sorted(list(FixDate(dt) for dt in dates.keys()))[-1] # grabs the last item (max in this case) action_dict[name] = [recent.keys()[0], dates[recent.keys()[0]]] # copies this into a new dictionary print name, recent.keys()[0], dates[recent.keys()[0]]
print action_date['Smith, John']
for name, action in action_dict.iteritems(): print name, action