Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active May 22, 2021 18:59
Show Gist options
  • Save fmasanori/06b0d3af4b398f754e62a7675e155004 to your computer and use it in GitHub Desktop.
Save fmasanori/06b0d3af4b398f754e62a7675e155004 to your computer and use it in GitHub Desktop.
Ordena Salários USP
#feito por https://twitter.com/guilhermeslcs
class Professor:
def __init__(self, nome, instituto, funcao, salario):
self.nome = nome
self.instituto = instituto
self.funcao = funcao
self.salario = salario
f = open("salarios.txt", "r")
professores = []
for line in f.read().split('\n'):
splited = line.split(":")
if "Nome" in splited[0]:
nome = splited[1]
elif "Instituto" in splited[0]:
inst = splited[1]
elif "Função" in splited[0]:
func = splited[1]
elif "Salário" in splited[0]:
salario = float(splited[1].replace(".","").replace(" ","").replace(",","."))
prof = Professor(nome=nome, instituto=inst, funcao=func, salario=salario)
professores.append(prof)
ordenados = sorted(professores, key=lambda x: x.salario, reverse=True)
for prof in ordenados:
print("Nome: "+prof.nome)
print("Instituto: "+prof.instituto)
print("Função: "+prof.funcao)
print("Salário: "+str(prof.salario))
print(" ")
@Guilhermeslucas
Copy link

Nice! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment