Skip to content

Instantly share code, notes, and snippets.

@brunobar79
Created October 18, 2013 20:28
Show Gist options
  • Select an option

  • Save brunobar79/7047728 to your computer and use it in GitHub Desktop.

Select an option

Save brunobar79/7047728 to your computer and use it in GitHub Desktop.
Function to get gender in spanish based on a name
def getGender(name):
name = name.strip()
name_tmp = name.split(" ")
name = name_tmp[0]
name = re.sub(r'[^a-zA-Z0-9]','',name)
#EXCEPTIONAL NAMES GOES HERE
other_female_names = ["clau","pame","flo","stephanie","penelope","pau","liz","solsito","ximme","xime","magali","mabel","maylen","deborah","pame","flo","nicole","jime","pao","mar","angie","karol","janet","pau","fioree","fiore","flor","yante","lau","laau","lau","roo","guadalupe","pilar","valen","ro","caro","caritto","maaite","maite","jazmin","irene","isabel","karen","mercedes","paz","marisol","ayelen","soledad","martu","maru","maruu","elizabeth","jennifer","mily","karem","nicol","sol","rocio","belen","luu","lu","vane","yazmin","carito","lizzette","celeste","vale","miriam","mirian","selene","abril","milagros","belu","nanu","anahi","carmen","giselle","margot","maite","matilde","ines"]
try:
if name.lower()[-1]=="a" or name.lower()[-1].lower()=="i" or name.lower()[-1].lower()=="y" or name.lower() in other_female_names:
return "F"
else:
return "M"
except:
return "M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment