fork download
  1. # trecho igual ao da pergunta
  2. def busca(setor):
  3. matriz = [["Adalberto Ferreira", "566", "Contabilidade", "(21)84564-5248"],
  4. ["Juliana Vasconcelos", "465", "RH", "(21)3555-4552"],
  5. ["Flavia Amorim", "565", "Contabilidade", "(21)2134-4845"]]
  6. nome = matriz[0][0], matriz[1][0], matriz[2][0]
  7. registro = matriz[0][1], matriz[1][1], matriz[2][1]
  8. setor = matriz[0][2], matriz[1][2], matriz[2][2]
  9. telefone = matriz[0][3], matriz[1][3], matriz[2][3]
  10.  
  11. # daqui pra baixo é o que você sugeriu mudar
  12. if setor == matriz[1][3]:
  13. return [nome[1][0:], registro[1][1:], telefone[1][3:]]
  14. else:
  15. return [[nome[0][0:], registro[0][1:], telefone[0][3:]], [nome[2][0:], registro[2][1:], telefone[2:][3:]]]
  16.  
  17. print(busca('Contabilidade')) # [['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]
  18. print(busca('RH')) # [['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]
  19. print(busca('Setor inexistente')) # [['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]
  20.  
Success #stdin #stdout 0.02s 9180KB
stdin
Standard input is empty
stdout
[['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]
[['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]
[['Adalberto Ferreira', '66', ')84564-5248'], ['Flavia Amorim', '65', ()]]