Felipe Concha
Felipe Concha

Reputation: 27

If Statement Simple

Is there a way to make this ELIF statement simplier, by the way this code doesnt work. The variable that change is APPOINTMENT

elif (rut == '80010900-0' and agental_launch != "" and 'TAL'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'IQQ'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'ANF'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'MJS'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'QTV'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'SVE'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'PMC'  in appointment) or
        (rut == '80010900-0' and agental_launch != "" and 'CHB'  in appointment):
        df.at[idx,'REBATE'] = round(int(monto_neto)*0.35)

Upvotes: 0

Views: 55

Answers (2)

Vasilis G.
Vasilis G.

Reputation: 7844

You can do it this way:

elif rut == '80010900-0' and agental_launch != "" and any(elem in appointment for elem in ['TAL','IQQ','ANF','MJS','QTV','SVE','PMC','CHB']):
     df.at[idx,'REBATE'] = round(int(monto_neto)*0.35)

Upvotes: 1

Jean-François Fabre
Jean-François Fabre

Reputation: 140188

use any for the last condition which becomes a one-liner:

elif rut == '80010900-0' and agental_launch != "" and any(x in appointment for x in ['TAL','IQQ','rest of strings to match...']):

Upvotes: 1

Related Questions