Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dictEx = {
- Student: [5,6]
- Student: [7,8]
- Student: [10,9]
- }
- class Student:
- def __init__(self, *args):
- self.__dict__ = dict(zip(['name', 'grade'], args))
- def getName(self):
- return self.name
- def __repr__(self):
- return "{}({})".format(self.__class__.__name__, ' '.join('{}:{}'.format(a, b) for a, b in self.__dict__.items()))
- dictEx = {
- Student('Tom', 10): [5,6],
- Student('James', 12): [7,8],
- Student('James', 7): [10,9],
- }
- new_dict = sorted(dictEx.items(), key=lambda x:(x[0].getName(), x[-1]))
- [(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