1s = {1: 1, 7: 2, 4: 2, 3: 1, 8: 1}
2k = dict(sorted(s.items(),key=lambda x:x[0],reverse = True))
3print(k)
1
2def sorted_dict_by_value(d: dict, reverse=False):
3 # Sort the dictionary items by values
4 marklist = sorted(d.items(), key=lambda x: x[1], reverse=reverse)
5 return dict(marklist)
6