-2
I’m starting in python and the current project (which is to apportion printers) has a lot of Elif, have any method I can reduce this in python? already I thank you.
This and the current code:
for i in range(len(list_nome_serial_valor)):
lista = list_nome_serial_valor[i][0]
if "SAME" in lista:
same = Setores("48","SAME")
same.adicionar_impressora(list_nome_serial_valor[i])
setores.append(same)
elif "PORTARIA CENTRAL" in lista or "RECEPCAO MULTIPROFISSIONAL" in lista:
rm = Setores("40","RECEPCAO MULTIPROFISSIONAL")
rm.adicionar_impressora(list_nome_serial_valor[i])
setores.append(rm)
elif "CONTABILIDADE" in lista:
contabilidade = Setores("27","CONTABILIDADE")
contabilidade.adicionar_impressora(list_nome_serial_valor[i])
setores.append(contabilidade)
#[mais elif's ...]
Obs: It separates the printer name and creates an object with all printers in the industry
First, do something like
('A' or 'B') in X
does not check whether A or B are in X; in fact the expression will first be evaluated'A' or 'B'
, who will always return'A'
and thus only check if A is in X, ignoring B. To check the two need to doA in X or B in X
.– Woss