from operator import itemgetter
def ordenar(dados, chave = 0, reverso = False):
return sorted(dados, key=itemgetter(chave), reverse=reverso)
dados = [(4, 3), (5, 1), (7, 2), (9, 0)]
print(ordenar(dados))
print(ordenar(dados, chave=1))
print(ordenar(dados, chave=1, reverso=True))
ZnJvbSBvcGVyYXRvciBpbXBvcnQgaXRlbWdldHRlcgoKZGVmIG9yZGVuYXIoZGFkb3MsIGNoYXZlID0gMCwgcmV2ZXJzbyA9IEZhbHNlKToKICByZXR1cm4gc29ydGVkKGRhZG9zLCBrZXk9aXRlbWdldHRlcihjaGF2ZSksIHJldmVyc2U9cmV2ZXJzbykKICAKZGFkb3MgPSBbKDQsIDMpLCAoNSwgMSksICg3LCAyKSwgKDksIDApXQoKcHJpbnQob3JkZW5hcihkYWRvcykpCnByaW50KG9yZGVuYXIoZGFkb3MsIGNoYXZlPTEpKQpwcmludChvcmRlbmFyKGRhZG9zLCBjaGF2ZT0xLCByZXZlcnNvPVRydWUpKQo=
[(4, 3), (5, 1), (7, 2), (9, 0)]
[(9, 0), (5, 1), (7, 2), (4, 3)]
[(4, 3), (7, 2), (5, 1), (9, 0)]