def assign_fields(x): # x is a list of words from a line. # create a list to hold the extracted fields, initialised to 'NA' by default. out = ['NA'] * 3 for word in x: # extract the name value (alphabetical) and insert in the first position. if word.isalpha(): out[0] = word else: # extract birth date (if any) # based on knowledge that all Dalton brothers were born before 1890 # and died after 1890 if (int(word) < 1890): out[1] = word elif (int(word) > 1890): out[2] = word # Returns a list format: [name, born, died] return out