dimanche 17 mai 2020

Python function with if-else statement outputting incorrectly

why is my function outputting incorrectly? I am thinking something is working wrong with the if-else statements but idk.

def standardize_gender(gen):
    gen = gen.strip()
    gen = gen.lower()

    if 'female' or 'f' or 'woman' or 'famale' or 'women' in gen:
        put = 'female'
    elif 'male' or 'man' or 'm' or 'men' in gen:
        put = 'male'
    elif 'nonbinary' or 'transgender' in gen:
        put = 'nonbinary_or_trans'
    else:
        put = np.nan
    return put

standardize_gender('male') #Outputs 'female'

Aucun commentaire:

Enregistrer un commentaire