fork download
  1. from operator import itemgetter
  2.  
  3. def ordenar(dados, chave = 0, reverso = False):
  4. return sorted(dados, key=itemgetter(chave), reverse=reverso)
  5.  
  6. dados = [(4, 3), (5, 1), (7, 2), (9, 0)]
  7.  
  8. print(ordenar(dados))
  9. print(ordenar(dados, chave=1))
  10. print(ordenar(dados, chave=1, reverso=True))
  11.  
Success #stdin #stdout 0.04s 9360KB
stdin
Standard input is empty
stdout
[(4, 3), (5, 1), (7, 2), (9, 0)]
[(9, 0), (5, 1), (7, 2), (4, 3)]
[(4, 3), (7, 2), (5, 1), (9, 0)]