Created
November 22, 2012 17:31
-
-
Save hltbra/4132293 to your computer and use it in GitHub Desktop.
sort by
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pprint | |
| pessoas = [ | |
| {'nome': 'Adolfo', 'estado': 'MG'}, | |
| {'nome': 'Igor', 'estado': 'CE'}, | |
| {'nome': 'Pedro', 'estado': 'RS'}, | |
| {'nome': 'Maria', 'estado': 'AC'}, | |
| ] | |
| def por_nome(pessoa1, pessoa2): | |
| return cmp(pessoa1['nome'], pessoa2['nome']) | |
| def por_estado(pessoa1, pessoa2): | |
| return cmp(pessoa1['estado'], pessoa2['estado']) | |
| pprint.pprint(sorted(pessoas, cmp=por_estado)) | |
| print("") | |
| pprint.pprint(sorted(pessoas, cmp=por_nome)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment