Guest User

Untitled

a guest
Dec 14th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. dictEx = {
  2. Student: [5,6]
  3. Student: [7,8]
  4. Student: [10,9]
  5. }
  6.  
  7. class Student:
  8. def __init__(self, *args):
  9. self.__dict__ = dict(zip(['name', 'grade'], args))
  10. def getName(self):
  11. return self.name
  12. def __repr__(self):
  13. return "{}({})".format(self.__class__.__name__, ' '.join('{}:{}'.format(a, b) for a, b in self.__dict__.items()))
  14.  
  15. dictEx = {
  16. Student('Tom', 10): [5,6],
  17. Student('James', 12): [7,8],
  18. Student('James', 7): [10,9],
  19. }
  20. new_dict = sorted(dictEx.items(), key=lambda x:(x[0].getName(), x[-1]))
  21.  
  22. [(Student(grade:12 name:James), [7, 8]), (Student(grade:7 name:James), [10, 9]), (Student(grade:10 name:Tom), [5, 6])]
Add Comment
Please, Sign In to add comment