Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import attrgetter
- class Usuario:
- def __init__(self, id):
- self.id = id
- def __repr__(self):
- return 'Usuario({})'.format(self.id)
- usuarios = [Usuario(13), Usuario(2), Usuario(11), Usuario(7)]
- print(usuarios)
- print(sorted(usuarios, key=lambda u: u.id))
- print('')
- print(sorted(usuarios, key=attrgetter('id')))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement