Если заявление простое - PullRequest
0 голосов
/ 25 октября 2019

Есть ли способ упростить этот оператор ELIF, так как этот код не работает. Переменная, которая изменяется, является 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)

Ответы [ 2 ]

1 голос
/ 25 октября 2019

Вы можете сделать это следующим образом:

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)
1 голос
/ 25 октября 2019

используйте any для последнего условия, которое становится однострочным:

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