Skip to content

Instantly share code, notes, and snippets.

Created Dec 12, 2009
What would you like to do?
def parse_name(name):
#delete (nicknames)
name = re.sub("\(.*?\)", "", name)
names = name.split(" ")
first_name = names[0]
if len(names) > 2:
middle_names = [names[1]]
for i, n in enumerate(names[2:]):
if"\w\.$", n.strip()):
else: break
middle_name = " ".join(middle_names)
last_name = " ".join(names[i+2:])
middle_name = ""
last_name = names[1]
#steal jr.s or sr.s
suffix = re.findall(", (\w*?)\.", last_name) or ""
if suffix:
suffix = suffix[0]
last_name = re.sub(", \w*?\.", "", last_name)
return (first_name, middle_name, last_name, suffix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment